diff --git a/flickrapi/auth.py b/flickrapi/auth.py index 475b06c..c535daa 100644 --- a/flickrapi/auth.py +++ b/flickrapi/auth.py @@ -18,13 +18,14 @@ import random import os.path import sys -import webbrowser import six from requests_toolbelt import MultipartEncoder import requests from requests_oauthlib import OAuth1 +from requests_futures.sessions import FuturesSession + from . import sockutil, exceptions, html from .exceptions import FlickrError @@ -149,7 +150,7 @@ def has_level(self, access_level): class OAuthFlickrInterface(object): """Interface object for handling OAuth-authenticated calls to Flickr.""" - session = requests.Session() + session = FuturesSession() REQUEST_TOKEN_URL = "https://www.flickr.com/services/oauth/request_token" AUTHORIZE_URL = "https://www.flickr.com/services/oauth/authorize" @@ -251,16 +252,18 @@ def do_request(self, url, params=None): data=params, auth=self.oauth) + response = req.result() + # check the response headers / status code. - if req.status_code != 200: - self.log.error('do_request: Status code %i received, content:', req.status_code) + if response.status_code != 200: + self.log.error('do_request: Status code %i received, content:', response.status_code) - for part in req.text.split('&'): + for part in response.text.split('&'): self.log.error(' %s', urllib_parse.unquote(part)) - raise exceptions.FlickrError('do_request: Status code %s received' % req.status_code) + raise exceptions.FlickrError('do_request: Status code %s received' % response.status_code) - return req.content + return response.content def do_upload(self, filename, url, params=None, fileobj=None): """Performs a file upload to the given URL with the given parameters, signed with OAuth. @@ -293,16 +296,18 @@ def do_upload(self, filename, url, params=None, fileobj=None): self.log.debug('POST %s', auth) req = self.session.post(url, data=m, headers=auth) + response = req.result() + # check the response headers / status code. - if req.status_code != 200: - self.log.error('do_upload: Status code %i received, content:', req.status_code) + if response.status_code != 200: + self.log.error('do_upload: Status code %i received, content:', response.status_code) - for part in req.text.split('&'): + for part in response.text.split('&'): self.log.error(' %s', urllib_parse.unquote(part)) - raise exceptions.FlickrError('do_upload: Status code %s received' % req.status_code) + raise exceptions.FlickrError('do_upload: Status code %s received' % response.status_code) - return req.content + return response.content @staticmethod def parse_oauth_response(data): @@ -397,6 +402,7 @@ def auth_via_browser(self, perms=u'read'): Updates the given request_token by setting the OAuth verifier. """ + import webbrowser # The HTTP server may have been started already, but we're not sure. Just start # it if it needs to be started.