web client urllib/httplib question

Jeremy Hylton jeremy at beopen.com
Fri Oct 13 18:40:22 EDT 2000


[Ned 3k writes:]
> Just wondering if anyone has run into the same problem as me with the
> web client module urllib. I can't figure out how to send headers. There
> is a method in the httplib module to send headers with a request, but
> this module dosen't have the functionality of the urllib module.

The urllib module's URLopener class does support this feature, albeit
not as part of the standard urlopen function.  If you create an
instance of URLopener (or FancyURLopener), you can use its addheader
method to add headers and then call its open method:
    
    fuo.addheader('Accept', 'sound/basic')
    fuo.open('http://funkymusak.com/sound')

urllib2 does not currently support this in any useful way, although it
would be possible to append to the addheaders attribute of an
OpenerDirector. 

Jeremy




More information about the Python-list mailing list