Tweepy SSLError regarding ssl certificate

橙三吉。 提交于 2019-12-09 01:06:51

问题


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([('SSL routines', 'ssl3_get_server_certificate', 'certificate verify failed')],)",)

My code is like this.

auth = tweepy.AppAuthHandler(consumer_key, consumer_secret) api = tweepy.API(auth,wait_on_rate_limit=True, wait_on_rate_limit_notify=True)

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.


回答1:


In streaming.py, adding verify = False in line# 105 did the trick for me as shown below. Though it is not advisable to use this approach as it makes the connection unsafe. Haven't been able to come up with a workaround for this yet.

stream = Stream(auth, listener, verify = False)



回答2:


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)

Edit:

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'




回答3:


First, verify if you can access twitter just using a proxy configuration. If so, you can modify this line on your code to include a proxy URL:

self.api = tweepy.API(self.auth)



回答4:


Adding verify=False will ignore the validation that has to be made and all the data will be transferred in plain text without any encryption.

pip install certifi

The above installation fixes the bad handshake and ssl error.



来源:https://stackoverflow.com/questions/37349419/tweepy-sslerror-regarding-ssl-certificate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!