python3 urlopen(...).read() returns bytes

ajaksu ajaksu at
Mon Dec 22 23:41:49 CET 2008

On Dec 22, 8:25 pm, Christian Heimes <li... at> wrote:
> It's not possible unless you know the encoding of the bytes. Network io
> only returns byte and you must encode it explicitly.
> There is no generic and simple way to detect the encoding of a remote
> site. Sometimes the encoding is mentioned in the HTTP header, sometimes
> it's embedded in the <head> section of the HTML document.

That said, a "decode to declared HTTP header encoding" version of
urlopen could be useful to give some users the output they want (text
from network io) or to make it clear why bytes is the safe way.


More information about the Python-list mailing list