From: Menno Smits Date: Mon, 12 Jan 2015 10:59:37 +0000 (+1300) Subject: Fixed livetest/interact OAUTH handling under Python 3 X-Git-Tag: 0.12^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1c21dee7e1578571349db4039c6ac7852368741a;p=imapclient.git Fixed livetest/interact OAUTH handling under Python 3 Fixes #130. --- diff --git a/imapclient/config.py b/imapclient/config.py index b3eb3b9..3ddd10f 100644 --- a/imapclient/config.py +++ b/imapclient/config.py @@ -6,7 +6,8 @@ except ImportError: from configparser import SafeConfigParser, NoOptionError import imapclient -import urllib +from .six.moves.urllib.request import urlopen +from .six.moves.urllib.parse import urlencode try: import json @@ -66,13 +67,13 @@ def parse_config_file(path): def refresh_oauth2_token(client_id, client_secret, refresh_token): if not json: raise RuntimeError("livetest OAUTH2 functionality relies on 'json' module") - post = dict(client_id=client_id, - client_secret=client_secret, - refresh_token=refresh_token, - grant_type='refresh_token') - response = urllib.urlopen('https://accounts.google.com/o/oauth2/token', - urllib.urlencode(post)).read() - return json.loads(response)['access_token'] + post = dict(client_id=client_id.encode('ascii'), + client_secret=client_secret.encode('ascii'), + refresh_token=refresh_token.encode('ascii'), + grant_type=b'refresh_token') + response = urlopen('https://accounts.google.com/o/oauth2/token', + urlencode(post).encode('ascii')).read() + return json.loads(response.decode('ascii'))['access_token'] # Tokens are expensive to refresh so use the same one for the duration of the process. _oauth2_cache = {}