views:

73

answers:

1

I can't seem to find how to do this anywere, I am trying to set multiple headers with python's mechanize module, such as:

br.addheaders = [('user-agent', '   Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3')]
br.addheaders = [('accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]

But it seems that it only takes the last br.addheaders.. so it only shows the 'accept' header, not the 'user-agent' header, which leads me to believe that each call to 'br.addheaders' overwrites any previous calls to this.. I can't figure the syntax to include 2 or more headers so I would greatly appreciate any help..

I am using this website to test headers output:

http://www.ericgiguere.com/tools/http-header-viewer.html

+1  A: 

According to http://wwwsearch.sourceforge.net/mechanize/doc.html#adding-headers, the syntax would be

br.addheaders = [('user-agent', '   Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3'),
('accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]

That is, make a list of header tuples.

levity37
thanks.. I tried that before but it didn't work, maybe i made some other syntax error without realizing it.. will try it again.. I need to bookmark that api page since its really confusing how to get to it (at least to me) from the main mechanize page that comes up in google
Rick
that works.. thanks for the help, dumb question on my part
Rick