From fc54a031dc5178be783b5fea9c31910b8dd42093 Mon Sep 17 00:00:00 2001 From: Thijs Triemstra Date: Thu, 26 Jan 2017 20:34:52 +0100 Subject: [PATCH 1/2] only import the webbrowser module when needed --- flickrapi/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flickrapi/auth.py b/flickrapi/auth.py index 475b06c..16f2b4c 100644 --- a/flickrapi/auth.py +++ b/flickrapi/auth.py @@ -18,7 +18,6 @@ import random import os.path import sys -import webbrowser import six from requests_toolbelt import MultipartEncoder @@ -397,6 +396,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. From db33a4999f7367f84d4074676835c434606c8bea Mon Sep 17 00:00:00 2001 From: Thijs Triemstra Date: Mon, 30 Jan 2017 22:55:08 +0100 Subject: [PATCH 2/2] use FutureSession --- flickrapi/auth.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/flickrapi/auth.py b/flickrapi/auth.py index 16f2b4c..c535daa 100644 --- a/flickrapi/auth.py +++ b/flickrapi/auth.py @@ -24,6 +24,8 @@ import requests from requests_oauthlib import OAuth1 +from requests_futures.sessions import FuturesSession + from . import sockutil, exceptions, html from .exceptions import FlickrError @@ -148,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" @@ -250,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. @@ -292,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):