Skip to content

Instantly share code, notes, and snippets.

@ptone
Created April 14, 2013 15:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ptone/8dddb3196e59af60908f to your computer and use it in GitHub Desktop.
from pip.backwardcompat import (WindowsError, BytesIO,
Queue, urlparse,
URLError, HTTPError, u,
product, url2pathname, ssl,
Empty as QueueEmpty, get_http_message_param)
from pip.download import urlopen, path_to_url2, url_to_path, geturl, Urllib2HeadRequest
url = 'http://www.dabeaz.com/ply/'
resp = urlopen(url)
headers = resp.info()
charset = get_http_message_param(headers, 'charset', 'latin-1')
contents = resp.read()
contents.decode('utf-8')
# UnicodeDecodeError: 'utf8' codec can't decode byte 0xf8 in position 10831: invalid start byte
contents.decode('latin-1')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment