我正在使用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.0
和certifi == 2018.11.29
所以我要检查的第一件事是你的版本是否更旧(特别是certifi
)。
此外,如果这是由certifi引起的,您应该能够通过重置请求对共享系统信任库使用的信任存储来解决,您可以通过运行以下命令找到路径:
python3 -c 'import ssl; print(ssl.get_default_verify_paths())'
寻找cafile
或openssl_cafile
的值然后(用获得的值替换$cafile
):
export REQUESTS_CA_BUNDLE=$cafile
另见this bug。