Fix reading URI under Py3
Change-Id: Id9c9fa8b8a311feeae13f8ec11b7abb29a1d9e87
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
import cgi
|
import cgi
|
||||||
import datetime
|
import datetime
|
||||||
import gzip
|
import gzip
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
@@ -105,6 +106,8 @@ def read_uri(uri):
|
|||||||
req = six.moves.urllib.request.Request(
|
req = six.moves.urllib.request.Request(
|
||||||
url=uri, headers={'User-Agent': random.choice(user_agents)})
|
url=uri, headers={'User-Agent': random.choice(user_agents)})
|
||||||
fd = six.moves.urllib.request.urlopen(req)
|
fd = six.moves.urllib.request.urlopen(req)
|
||||||
|
if six.PY3:
|
||||||
|
fd = io.TextIOWrapper(fd)
|
||||||
raw = fd.read()
|
raw = fd.read()
|
||||||
fd.close()
|
fd.close()
|
||||||
return raw
|
return raw
|
||||||
|
Reference in New Issue
Block a user