Skip to content

Commit 336138f

Browse files
fix to work in both python 2 and 3
1 parent 4b1a771 commit 336138f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

alchemyapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
try:
55
from urllib.request import urlopen
66
from urllib.parse import urlparse
7-
from urllib.quote import urlquote
7+
from urllib.parse import quote as urlquote
88
except ImportError:
9+
print("IMPORT ERROR")
910
from urlparse import urlparse
1011
from urllib2 import urlopen
1112
from urllib2 import quote as urlquote
@@ -571,9 +572,8 @@ def __analyze(self, url, options):
571572

572573
try:
573574
#build the request with uri encoding
574-
req = urlparse(url)
575-
page = urlopen(req.geturl())
576-
return json.load(page)
575+
page = urlopen(url).read().decode("utf-8")
576+
return json.loads(page)
577577
except Exception as e:
578578
print('error for url: ', url)
579579
print(e)

0 commit comments

Comments
 (0)