the return of urllib.request.urlopen("", params)

Steven D'Aprano steven at
Wed Apr 1 06:49:30 CEST 2009

On Tue, 31 Mar 2009 21:17:29 -0700, tunpishuang wrote:

> hey guys , i'm new in python i got a little problem that get me
> confused...
> i wanna do an uthentication of an login page , here is the example from
> the python lib ref. :
>>>> import urllib.request
>>>> import urllib.parse
>>>> params = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) f
>>>> = urllib.request.urlopen("" %
>>>> params) print(
> i wanted to know what the the return value of f ,,if it's an instance of
> http.client.HTTPResponse
> and why the return source of the web page is quote like this :
> b'<html></html>'

Looks like you are using Python 3.0.

In Python 2.x, the native string type is bytes (commonly called "ASCII"). 
So a string of bytes is displayed like this:


and a string of Unicode characters is displayed like this:


In Python 3.0, the native string type is unicode, but HTTP responses are 
bytes. Bytes are displayed like this:


and strings of characters like this:


Notice that the B on the outside of the quotes is not part of the string, 
it is part of the display format, just like the quotes themselves.

You can convert the bytes into a string by just called str() on the 

# untested
>>> print(str(

This should work for the simple case, although once you start getting 
more complicated strings, with international (non-English) characters, 
you will need to supply an encoding.

Does this help?


More information about the Python-list mailing list