From 1c21dee7e1578571349db4039c6ac7852368741a Mon Sep 17 00:00:00 2001 From: Menno Smits Date: Mon, 12 Jan 2015 23:59:37 +1300 Subject: [PATCH] Fixed livetest/interact OAUTH handling under Python 3 Fixes #130. --- imapclient/config.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) 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 = {} -- 2.43.0