SSL Error in Twython GET

混江龙づ霸主 提交于 2019-12-12 01:22:15

问题


I am playing with the twython and requests packages and found something strange which is blocking my code to retrive the tweets. I am working behind the firewall if it helps.

Code:

from twython import Twython
t = Twython(app_key=consumer_key,app_secret=consumer_secret,oauth_token=access_token,oauth_token_secret=access_secret)
a = t.search(q="@Benton",count=100)

import requests
requests.get("https://github.com/timeline.json",verify=False)

Error from Twython Request:

SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Success from Requests

Response [200]

So it seems that "cacert.pem" is working fine for Request library but not for Twython. I am assuming the Twython calls the requests to get the verification for the credentials. Is it possible to use "Verify=False" in the twyhton call for search in Twitter.


回答1:


If you're using Twython 3.0.0, docs can be found at https://twython.readthedocs.org/en/latest/usage/advanced_usage.html#manipulate-the-request-headers-proxies-etc on how to modify the request.

If you're too lazy to look, here is code that will work.

from twython import Twython

client_args = {
    'verify': False
}

twitter = Twython(APP_KEY, APP_SECRET
                  OAUTH_TOKEN, OAUTH_TOKEN_SECRET
                  client_args=client_args)

a = twitter.search(q="@Benton",count=100)



回答2:


I think the problem is with the firewall rather than with Twython. I get this error on networks that have blocked Twitter.



来源:https://stackoverflow.com/questions/17091822/ssl-error-in-twython-get

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