From 456efaefe14cb0e9167e8f91a136bed6d5cd096a Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Thu, 22 Sep 2011 17:56:28 -0400 Subject: [PATCH] Try ISO-8859-1 if unicode fails --- web.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web.py b/web.py index 8017ac7..dbeb5b5 100755 --- a/web.py +++ b/web.py @@ -21,7 +21,11 @@ def get(uri): if not uri.startswith('http'): return 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() return bytes @@ -38,7 +42,11 @@ def post(uri, query): return data = urllib.parse.urlencode(query) 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() return bytes