1

Is there any Python HTTP library that helps to imitate one of popular web-browser and has HTTPS support? I would like to define the order of HTTP headers, the presence of each exact header, the order of cookies values - everything that relates to "fingerprint" of a browser. We need that to test specific web server.

1
  • For httplib, if you don't add headers, will the header contains anything you don't want? Commented Sep 17, 2012 at 11:26

2 Answers 2

2

httplib.request will take an OrderedDict for headers. Some headers will be added automatically for protocol compliance, which will be left out if you specify them in your supplied headers.

Take a look at the putheader and _send_request methods, which you could override if their behaviour didn't suit your purposes.

>>> import httplib
>>> from collections import OrderedDict
>>> h = OrderedDict(('X-A','a'),('X-B','b'),('X-C','c'))
>>> c = httplib.HTTPConnection('localhost')
>>> c.set_debuglevel(1)
>>> r = c.request('GET','/','',h)
send: 'GET / HTTP/1.1\r\nHost: localhost\r\nAccept-Encoding: identity\r\nX-A: a\r\nX-B: b\r\nX-C: c\r\n\r\n'
Sign up to request clarification or add additional context in comments.

1 Comment

httplib also has some HTTPS support.
0

Check out Requests which is very easy to work with and has all you need. Alternatively you can drive web browser itself from Python using Selenium

1 Comment

One of your link seems to be from your local network. Well, at least I cannot access.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.