[Tutor] encoding question

Alex Kleider akleider at sonic.net
Sat Jan 4 21:44:29 CET 2014


On 2014-01-04 12:01, eryksun wrote:
> On Sat, Jan 4, 2014 at 2:26 PM, Alex Kleider <akleider at sonic.net> 
> wrote:
.....
> 
> b'\xe1' is Latin-1. Look in the response headers:
> 
>     url = 
> 'http://api.hostip.info/get_html.php?ip=201.234.178.62&position=true'
> 
>     >>> response = urllib.request.urlopen(url)
>     >>> response.headers.get_charsets()
>     ['iso-8859-1']
> 
>     >>> encoding = response.headers.get_charsets()[0]
>     >>> sp = response.read().decode(encoding).splitlines()
>     >>> sp[1]
>     'City: Bogotá'

Thank you very much.  Now things are more clear.
cheers,
alex


More information about the Tutor mailing list