From: Aaron Hill Date: Fri, 16 Aug 2013 19:57:05 +0000 (-0400) Subject: Use Requests's OAuth for XAuth X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e05eae339ce941c76cc4352d83b531fe6e2954f9;p=tweepy.git Use Requests's OAuth for XAuth --- 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)