gpt4 book ai didi

python - 发出请求时python中的SSL认证错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:27:55 25 4
gpt4 key购买 nike

我正在使用 gspread 访问谷歌电子表格,但它显示 SSLError。

当我使用请求库时,类似的事情发生了。

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)

gc = gspread.authorize(credentials)`

错误是:

SSLCertVerificationError                  Traceback (most recent call last)
<ipython-input-1-87ec55398e31> in <module>
7 credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
8
----> 9 gc = gspread.authorize(credentials)


SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)

最佳答案

它适用于 requests == 2.21.0certifi == 2018.11.29 所以我首先要检查的是你的版本是否较旧(尤其是 certifi)。

此外,如果这是由 certifi 引起的,您应该能够通过将 requests 使用的信任库重置为共享系统信任库来解决,您可以找到运行路径:

python3 -c 'import ssl; print(ssl.get_default_verify_paths())'

查找 cafileopenssl_cafile 的值,然后(将 $cafile 替换为获得的值):

export REQUESTS_CA_BUNDLE=$cafile

另见 this bug .

关于python - 发出请求时python中的SSL认证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55304648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com