http://docs.python.org/howto/urllib2.html#headers - error

Hello, There is an error on: http://docs.python.org/howto/urllib2.html#headers There is : headers = { 'User-Agent' : user_agent } req = urllib2.Request(url, data, *headers*) If you want to add header, you should use request.add_header method: req = urllib2.Request(url, data, headers) *req.add_header(**'User-Agent', user_agent**)* Maxim.

Hello Maxim, On Fri, Jul 27, 2012 at 11:16 AM, Maxim Boyarskiy <mboyarskiy@thumbtack.net> wrote:
headers = { 'User-Agent' : user_agent } req = urllib2.Request(url, data, headers)
If you want to add header, you should use request.add_header method:
req = urllib2.Request(url, data, headers) req.add_header('User-Agent', user_agent)
Are you sure about that? did you try and it failed? Because from urrlib2.Request doc at http://docs.python.org/library/urllib2.html#urllib2.Request we can read: "headers should be a dictionary, and will be treated as if add_header() was called with each key and value as arguments." Regards, -- Sandro Tosi (aka morph, morpheus, matrixhasu) My website: http://matrixhasu.altervista.org/ Me at Debian: http://wiki.debian.org/SandroTosi
participants (2)
-
Maxim Boyarskiy
-
Sandro Tosi