Skip to content

Commit 28c2588

Browse files
kratos83braincore
authored andcommitted
Fix token sesssion parsing in PY3.
1 parent f45219f commit 28c2588

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

dropbox/session.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pkg_resources
2-
import six
32
import ssl
3+
import sys
44

55
import requests
66
from requests.adapters import HTTPAdapter
@@ -41,20 +41,16 @@ def pinned_session(pool_maxsize=8):
4141
import time
4242
import urllib
4343

44-
try:
45-
from urlparse import parse_qs
46-
except ImportError:
47-
# fall back for Python 2.5
48-
from cgi import parse_qs
49-
5044
from . import rest
5145

52-
if six.PY3:
53-
url_path_quote = urllib.parse.quote
54-
url_encode = urllib.parse.urlencode
55-
else:
46+
if six.PY2:
47+
from urlparse import parse_qs
5648
url_path_quote = urllib.quote
5749
url_encode = urllib.urlencode
50+
else:
51+
from urllib.parse import parse_qs
52+
url_path_quote = urllib.parse.quote
53+
url_encode = urllib.parse.urlencode
5854

5955

6056
class OAuthToken(object):
@@ -320,13 +316,19 @@ def _parse_token(cls, s):
320316
if not params:
321317
raise ValueError("Invalid parameter string: %r" % s)
322318

319+
if six.PY2:
320+
oauth_token_key = 'oauth_token'
321+
oauth_token_secret_key = 'oauth_token_secret'
322+
else:
323+
oauth_token_key = b'oauth_token'
324+
oauth_token_secret_key = b'oauth_token_secret'
323325
try:
324-
key = params['oauth_token'][0]
326+
key = params[oauth_token_key][0]
325327
except Exception:
326328
raise ValueError("'oauth_token' not found in OAuth request.")
327329

328330
try:
329-
secret = params['oauth_token_secret'][0]
331+
secret = params[oauth_token_secret_key][0]
330332
except Exception:
331333
raise ValueError("'oauth_token_secret' not found in "
332334
"OAuth request.")

0 commit comments

Comments
 (0)