Johanna Larsson
Johanna Larsson

Reputation: 10761

Python - The request headers for mechanize

I am looking for a way to view the request (not response) headers, specifically what browser mechanize claims to be. Also how would I go about manipulating them, eg setting another browser?

Example:

import mechanize
browser = mechanize.Browser()
# Now I want to make a request to eg example.com with custom headers using browser

The purpose is of course to test a website and see whether or not it shows different pages depending on the reported browser.

It has to be the mechanize browser as the rest of the code depends on it (but is left out as it's irrelevant.)

Upvotes: 4

Views: 5933

Answers (3)

Yuda Prawira
Yuda Prawira

Reputation: 12471

you can modify referer too...

br.addheaders = [('Referer', 'http://google.com')]

Upvotes: 2

Duncan
Duncan

Reputation: 95712

You've got an answer on how to change the headers, but if you want to see the exact headers that are being used try using a proxy that displays the traffic. e.g. Fiddler2 on windows or see this question for some Linux altenatives.

Upvotes: 2

rkhayrov
rkhayrov

Reputation: 10260

browser.addheaders = [('User-Agent', 'Mozilla/5.0 blahblah')]

Upvotes: 8

Related Questions