Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

only import the webbrowser module when needed #78

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions flickrapi/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down