diff options
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 4ff96303..459cae2c 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -199,8 +199,12 @@ class PackageIndex(Environment): base = f.url # handle redirects page = f.read() - if sys.version_info >= (3,) and not isinstance(f, urllib2.HTTPError): - charset = f.headers.get_param('charset') or 'latin-1' + if not isinstance(page, str): # We are in Python 3 and got bytes. We want str. + if isinstance(f, urllib2.HTTPError): + # Errors have no charset, assume latin1: + charset = 'latin-1' + else: + charset = f.headers.get_param('charset') or 'latin-1' page = page.decode(charset, "ignore") f.close() for match in HREF.finditer(page): |