Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28cc444

Browse files
committed
Fix oauth2.0 to work with python 3
1 parent a43f5ec commit 28cc444

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gluon/contrib/login_methods/oauth20_account.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def accessToken(self):
174174
open_url = None
175175
opener = self.__build_url_opener(self.token_url)
176176
try:
177-
open_url = opener.open(self.token_url, urlencode(data), self.socket_timeout)
177+
open_url = opener.open(self.token_url, urlencode(data).encode(), self.socket_timeout)
178178
except urllib2.HTTPError as e:
179179
tmp = e.read()
180180
raise Exception(tmp)
@@ -185,7 +185,13 @@ def accessToken(self):
185185
if open_url:
186186
try:
187187
data = open_url.read()
188-
resp_type = open_url.info().gettype()
188+
189+
try:
190+
resp_type = open_url.info().get_content_type()
191+
except:
192+
# Old python 2 version. This does not work for python3
193+
resp_type = open_url.info().gettype()
194+
189195
# try json style first
190196
if not resp_type or resp_type[:16] == 'application/json':
191197
try:

0 commit comments

Comments
 (0)