关于 ssl 证书的 Tweepy SSLError [英] Tweepy SSLError regarding ssl certificate
问题描述
我正在 Python 中使用 Tweepy 运行 REST API(搜索 API).我在家里完成了这个程序,它完全没问题.但现在我正在不同的网络中处理这个问题,我收到了错误消息.
I am running a REST API (Search API) with Tweepy in Python. I worked the program at home and it's totally fine. But now I am working on this in different networks and I got the error message.
SSLError: ("bad handshake: Error([('SSLroutines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)
我的代码是这样的.
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)api = tweepy.API(auth,wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
我找到了这篇文章Python 请求引发 SSLError并设置以下代码(verify = false
)可能是一个快速的解决方案.有谁知道如何在 tweepy 中做到这一点或其他方式?谢谢.
I found this post
Python Requests throwing up SSLError
and set the following code (verify = false
) may be a quick solution. Does anyone know how to do it or other ways in tweepy? Thank you.
推荐答案
我遇到了同样的问题,不幸的是唯一有效的是在 Tweepy 的 auth.py 中设置 verify=False(对我来说 Tweepy 位于 /anaconda3/lib/python3.6/site-packages/tweepy
在我的 Mac 上):
I ran into the same problem and unfortunately the only thing that worked was setting verify=False in auth.py in Tweepy (for me Tweepy is located in /anaconda3/lib/python3.6/site-packages/tweepy
on my Mac):
resp = requests.post(self._get_oauth_url('token'),
auth=(self.consumer_key,
self.consumer_secret),
data={'grant_type': 'client_credentials'},
verify=False)
在企业防火墙后面,存在证书问题.在 Chrome 中,转到设置--> 高级--> 证书并下载您的公司 CA 证书.然后,在 Tweepy binder.py 中,在 session = requests.session()
下添加
Behind a corporate firewall, there is a certificate issue. In chrome go to settings-->advanced-->certificates and download your corporate CA certificate. Then, in Tweepy binder.py, right under session = requests.session()
add
session.verify = 'path_to_corporate_certificate.cer'
这篇关于关于 ssl 证书的 Tweepy SSLError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!