Use Requests's OAuth for XAuth
authorAaron Hill <aa1ronham@gmail.com>
Fri, 16 Aug 2013 19:57:05 +0000 (15:57 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sun, 27 Apr 2014 02:03:11 +0000 (22:03 -0400)
tweepy/auth.py

index a8056bbd5f4a6cd8298e2ef3ac3fe4e10f349f18..34a488dda46e4da92da3f523c5e226d3ec21467d 100644 (file)
@@ -10,6 +10,7 @@ from tweepy.api import API
 import requests
 from requests_oauthlib import OAuth1Session, OAuth1
 from requests.auth import AuthBase
+from urlparse import parse_qs
 
 class AuthHandler(object):
 
@@ -100,13 +101,14 @@ class OAuthHandler(AuthHandler):
         """
         try:
             url = self._get_oauth_url('access_token', secure=True)
-            request = oauth.OAuthRequest.from_consumer_and_token(oauth_consumer=self._consumer, http_method='POST', http_url=url, parameters={'x_auth_mode': 'client_auth',
-             'x_auth_username': username,
-             'x_auth_password': password})
-            request.sign_request(self._sigmethod, self._consumer, None)
-            resp = urlopen(Request(url, data=request.to_postdata()))
-            self.access_token = oauth.OAuthToken.from_string(resp.read())
-            return self.access_token
+            oauth = OAuth1(self.consumer_key, client_secret=self.consumer_secret)
+            r = requests.post(url=url, auth=oauth, headers={'x_auth_mode':
+                'client_auth', 'x_auth_username': username, 'x_auth_password':
+                password})
+
+            print r.content
+            credentials = parse_qs(r.content)
+            return (credentials.get('oauth_token')[0], credentials.get('oauth_token_secret')[0])
         except Exception as e:
             raise TweepError(e)