From e05eae339ce941c76cc4352d83b531fe6e2954f9 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 16 Aug 2013 15:57:05 -0400 Subject: [PATCH] Use Requests's OAuth for XAuth --- tweepy/auth.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tweepy/auth.py b/tweepy/auth.py index a8056bb..34a488d 100644 --- a/tweepy/auth.py +++ b/tweepy/auth.py @@ -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) -- 2.25.1