由于Windows上的信任存储为空,pythontreq失败,并出现Twisted/OpenSSL错误

2024-10-06 13:01:35 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在http://www.google.com上运行以下示例代码时,它可以正常工作 但是当我尝试https://www.google.com时,我得到了一个错误:

Requesting https://www.google.com

Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
Failure: twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure <class 'OpenSSL.SSL.Error'>>]

我使用的是python2.7.8、twisted 14.0.2、service_identity 14.0.0、treq 0.2.1、OpenSSL 0.14

^{pr2}$

提前谢谢!在


Tags: 代码httpscomhttp示例failurewww错误
1条回答
网友
1楼 · 发布于 2024-10-06 13:01:35

这里的问题很可能是您没有选择任何信任根,因此OpenSSL无法对连接进行身份验证。在

您可以通过执行pip install certifi获得OpenSSL可以使用的格式中的一些信任根,然后将SSL_CERT_FILE环境变量设置为指向python -m certifi的输出。在Python中,您可以在脚本的最上面使用import certifi; os.environ["SSL_CERT_FILE"] = certifi.where()来实现这一点(在导入任何OpenSSL绑定之前)。在

相关问题 更多 >