Twython oauth1 authentication SSL3 error

275 Views Asked by At

I am trying to rebuild the example for the streaming API, using the following code

from twython import Twython
from twython import TwythonStreamer

APP_SECRET = 'XXXXX'
APP_KEY = 'XXXXX'

# from https://stackoverflow.com/questions/17091822/ssl-error-in-twython-get
client_args = {
    'verify': False
}

twitter = Twython(APP_KEY, APP_SECRET,client_args=client_args)
auth = twitter.get_authentication_tokens()
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']

print 'OAUTH_TOKEN = \''+auth['oauth_token']+'\''
print 'OAUTH_TOKEN_SECRET =\''+auth['oauth_token_secret']+'\''
print auth['auth_url']

I already followed the client_args hint found at: SSL Error in Twython GET

However it fails on me with the following error:

---------------------------------------------------------------------------
SSLError                                  Traceback (most recent call last)
<ipython-input-6-c21b30032283> in <module>()
      7 APP_KEY = 'XXX'
      8 twitter = Twython(APP_KEY, APP_SECRET,client_args=client_args)
----> 9 auth = twitter.get_authentication_tokens()
     10 OAUTH_TOKEN = auth['oauth_token']
     11 OAUTH_TOKEN_SECRET = auth['oauth_token_secret']

/Users/geoffreystoel/python/anaconda/lib/python2.7/site-packages/twython/api.pyc in get_authentication_tokens(self, callback_url, force_login, screen_name)
    267         if callback_url:
    268             request_args['oauth_callback'] = callback_url
--> 269         response = self.client.get(self.request_token_url, params=request_args)
    270 
    271         if response.status_code == 401:

/Users/geoffreystoel/python/anaconda/lib/python2.7/site-packages/requests/sessions.pyc in get(self, url, **kwargs)
    392 
    393         kwargs.setdefault('allow_redirects', True)
--> 394         return self.request('GET', url, **kwargs)
    395 
    396     def options(self, url, **kwargs):

/Users/geoffreystoel/python/anaconda/lib/python2.7/site-packages/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert)
    380             'allow_redirects': allow_redirects,
    381         }
--> 382         resp = self.send(prep, **send_kwargs)
    383 
    384         return resp

/Users/geoffreystoel/python/anaconda/lib/python2.7/site-packages/requests/sessions.pyc in send(self, request, **kwargs)
    483         start = datetime.utcnow()
    484         # Send the request
--> 485         r = adapter.send(request, **kwargs)
    486         # Total elapsed time of the request (approximately)
    487         r.elapsed = datetime.utcnow() - start

/Users/geoffreystoel/python/anaconda/lib/python2.7/site-packages/requests/adapters.pyc in send(self, request, stream, timeout, verify, cert, proxies)
    377         except (_SSLError, _HTTPError) as e:
    378             if isinstance(e, _SSLError):
--> 379                 raise SSLError(e)
    380             elif isinstance(e, TimeoutError):
    381                 raise Timeout(e)

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

What am I doing wrong? And secondly - is there a way to get the PIN programmatically? other than clicking the URL and copy pasting it in my code further down?

0

There are 0 best solutions below