Try ISO-8859-1 if unicode fails
This commit is contained in:
12
web.py
12
web.py
@@ -21,7 +21,11 @@ def get(uri):
|
|||||||
if not uri.startswith('http'):
|
if not uri.startswith('http'):
|
||||||
return
|
return
|
||||||
u = urllib.request.urlopen(uri)
|
u = urllib.request.urlopen(uri)
|
||||||
bytes = u.read().decode('utf-8')
|
bytes = u.read()
|
||||||
|
try:
|
||||||
|
bytes = bytes.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
bytes = bytes.decode('ISO-8859-1')
|
||||||
u.close()
|
u.close()
|
||||||
return bytes
|
return bytes
|
||||||
|
|
||||||
@@ -38,7 +42,11 @@ def post(uri, query):
|
|||||||
return
|
return
|
||||||
data = urllib.parse.urlencode(query)
|
data = urllib.parse.urlencode(query)
|
||||||
u = urllib.request.urlopen(uri, data)
|
u = urllib.request.urlopen(uri, data)
|
||||||
bytes = u.read().decode('utf-8')
|
bytes = u.read()
|
||||||
|
try:
|
||||||
|
bytes = bytes.decode('utf-8')
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
bytes = bytes.decode('ISO-8859-1')
|
||||||
u.close()
|
u.close()
|
||||||
return bytes
|
return bytes
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user