Skip to content

Commit

Permalink
encode('ascii') works for 2 and 3 (issue #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpuntaie committed Aug 25, 2020
1 parent f7f83e9 commit 48d3741
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions getmail-gmail-xoauth-tokens
Expand Up @@ -28,12 +28,12 @@ import json
import argparse
import time
try:
import urllib.request as urlrequest
import urllib.parse as urlparse
import urllib.request as urllibrequest
import urllib.parse as urllibparse
raw_input = input
except: #py2
import urllib as urlparse
urlrequest = urlparse
import urllib as urllibparse
urllibrequest = urllibparse


class OAuth2(object):
Expand All @@ -53,7 +53,7 @@ class OAuth2(object):
def query(self, params):
lst = []
for param in sorted(params.items(), key=lambda x: x[0]):
escaped = urlparse.quote(param[1], safe='~-._')
escaped = urllibparse.quote(param[1], safe='~-._')
lst.append('%s=%s' % (param[0], escaped))
return '&'.join(lst)

Expand All @@ -63,8 +63,8 @@ class OAuth2(object):
return '%s?%s' % (self.data['auth_uri'], self.query(params))

def get_response(self, url, params):
encoded = urlparse.urlencode(params)
response = urlrequest.urlopen(url, encoded).read()
encoded = urllibparse.urlencode(params).encode('ascii')
response = urllibrequest.urlopen(url, encoded).read()
return json.loads(response)

def update_config(self, d):
Expand Down

0 comments on commit 48d3741

Please sign in to comment.