Jonas Lejon
Jonas Lejon

Reputation: 3239

Set Host-header when using Python and urllib2

I'm using my own resolver and would like to use urllib2 to just connect to the IP (no resolving in urllib2) and I would like set the HTTP Host-header myself. But urllib2 is just ignoring my Host-header:

txheaders = { 'User-Agent': UA, "Host: ": nohttp_url }
robots = urllib2.Request("http://" + ip  + "/robots.txt", txdata, txheaders)

Upvotes: 7

Views: 5458

Answers (1)

Katriel
Katriel

Reputation: 123632

You have included ": " in the "Host" string.

txheaders = { "User-Agent": UA, "Host": nohttp_url }
robots = urllib2.Request("http://" + ip  + "/robots.txt", txdata, txheaders)

Upvotes: 10

Related Questions