SSL Error in Twython GET

2019-09-16 23:58发布

问题:

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.