Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 402
Jonas Lejon Avatar asked Aug 19 '10 10:08

Jonas Lejon


1 Answers

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

txheaders = { "User-Agent": UA, "Host": nohttp_url }
robots = urllib2.Request("http://" + ip  + "/robots.txt", txdata, txheaders)
like image 107
Katriel Avatar answered Nov 03 '22 00:11

Katriel