python - 为什么我不断收到 SSL : CERTIFICATE_VERIFY_FAILED] error when using API's?

标签 python api ssl ssl-certificate

我意识到,基本上每次我尝试使用基于 API 的库(quandl、pandas datareader 或只是用于搜索引擎的普通 Google API)时,我都会不断收到

exceptions.SSLError (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))

我尝试过更新 certifi、setuptools、requests 和基本上所有内容,但没有任何帮助。我已经下载了新的 cacert.pem 文件并替换了旧的文件,但它仍然给我错误。

这是一个代码示例和我收到的错误:

import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt

start_date = "2020-01-1"
end_date = "2020-12-31"

data = web.DataReader(name="TSLA", data_source='yahoo', start=start_date, end=end_date)
print(data)

requests.exceptions.SSLError: HTTPSConnectionPool(host='finance.yahoo.com', port=443): Max retries exceeded with url: /quote/TSLA/history?period1=1577847600&period2=1609469999&interval=1d&frequency=1d&filter=history (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997)')))

我正在使用:

  • Python 3.10.6(我之前使用的是 Python 3.8,大约两周前它可以工作,但在我更新计算机后它停止了,所以我更新到了最新版本的 Python)

  • 点 22.2.2

最佳答案

您可以尝试安装 certifi 库。

您可以像这样使用 pip 安装它。

pip install certifi

安装后即可使用此命令

/Applications/Python\ 3.10/install\ Certificates.command

只需将 python 版本更改为您环境中的版本即可

然后再次尝试运行您的程序。

这对我有用。

关于python - 为什么我不断收到 SSL : CERTIFICATE_VERIFY_FAILED] error when using API's?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73385267/

相关文章:

python - NLTK 认为命令是名词

python - 如何使用saved_model_cli查询tensorflow 'wide and deep'模型?

php - Javascript 比较数组中的字符串

web-services - 社交网络的 RESTful 设计

java - 尝试从远程 SSL 地址下载和设置证书以进行 WebSocket 连接,但出现 "Signature does not match"异常

ssl - 如何为tomcat导入公共(public)证书

python - 导入 scipy.special.expit 时出错

python - 消除for循环中的 "found"变量

java - 为什么我无法导入 GoogleSignInClient 类?

php - 尝试通过 PHP 访问 Parse 时出现 SSL 证书问题