![](/img/trans.png)
[英]Python ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)
[英]gspread error: SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] in python
我有几行以前一直工作到今天的代码(使用gspread)。 每当我运行以下代码时,我都会收到证书验证错误:
json_key = json.load(open('Sheetmodification_abc.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope)
gc = gspread.authorize(credentials)
wks = gc.open("googlespreadsheets").sheet1
这可能是什么原因,我该如何解决? 我一直在这里寻找解决方案: https : //github.com/burnash/gspread/issues/223
但是不了解提供的解决方案。
这是回溯:
---------------------------------------------------------------------------
SSLError Traceback (most recent call last)
C:\Users\Nathan\App_Finder_2.0.1.py in <module>()
142 gc = gspread.authorize(credentials)
143
--> 144 wks = gc.open("googlespreadsheets").sheet1
145
146 # 1. Retrieve app name
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\gspread\client.pyc in open(self, title)
143
144 """
--> 145 feed = self.get_spreadsheets_feed()
146
147 for elem in feed.findall(_ns('entry')):
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\gspread\client.pyc in get_spreadsheets_feed(self, visibility, projection)
229 visibility=visibility, projection=projection)
230
--> 231 r = self.session.get(url)
232 return ElementTree.fromstring(r.content)
233
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\gspread\httpsession.pyc in get(self, url, **kwargs)
73
74 def get(self, url, **kwargs):
---> 75 return self.request('GET', url, **kwargs)
76
77 def delete(self, url, **kwargs):
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\gspread\httpsession.pyc in request(self, method, url, data, headers)
65 except AttributeError:
66 raise Exception("HTTP method '{}' is not supported".format(method))
---> 67 response = func(url, data=data, headers=request_headers)
68
69 if response.status_code > 399:
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\api.pyc in get(url, params, **kwargs)
67
68 kwargs.setdefault('allow_redirects', True)
---> 69 return request('get', url, params=params, **kwargs)
70
71
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\api.pyc in request(method, url, **kwargs)
48
49 session = sessions.Session()
---> 50 response = session.request(method=method, url=url, **kwargs)
51 # By explicitly closing the session, we avoid leaving sockets open which
52 # can trigger a ResourceWarning in some cases, and look like a memory leak
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
463 }
464 send_kwargs.update(settings)
--> 465 resp = self.send(prep, **send_kwargs)
466
467 return resp
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\sessions.pyc in send(self, request, **kwargs)
571
572 # Send the request
--> 573 r = adapter.send(request, **kwargs)
574
575 # Total elapsed time of the request (approximately)
C:\Users\Nathan\AppData\Local\Enthought\Canopy\User\lib\site-packages\requests\adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
429 except (_SSLError, _HTTPError) as e:
430 if isinstance(e, _SSLError):
--> 431 raise SSLError(e, request=request)
432 elif isinstance(e, ReadTimeoutError):
433 raise ReadTimeout(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)
首先,我应该提到我在Windows上使用Python 2.7。 我发现,如果运行的脚本与您的脚本非常相似,而没有“ Administrator Privileges”,则Python会抛出SSLError异常(在我的情况下,ssl.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:590))。 使用“管理员权限”(CMD,“以管理员身份运行”)运行相同的脚本不会引发任何异常。
这可能与Windows防火墙有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.