开发者

urllib2 in Python 2.6.4: Any way to override windows hosts file?

开发者 https://www.devze.com 2022-12-25 06:22 出处:网络
I am using the urllib2 module in Python 2.6.4, running in Windows XP, to access a URL. I am making a post request, that does not involve cookies or https or anything too complicated. The domain is red

I am using the urllib2 module in Python 2.6.4, running in Windows XP, to access a URL. I am making a post request, that does not involve cookies or https or anything too complicated. The domain is redirected in my C:\WINDOWS\system32\drivers\etc\hosts file. However, I would like the request from urllib2 to go to the "real" domain and ignore the entry in the hosts file. Is there any easy and practical way to do this?

I would prefer if the request has the domain name in it, for example:

GET www.example.com/foo.html

rather than

GET 123.4开发者_如何学Python5.67.89/foo.html

Forget about that last part if you want. I don't need to be that specific about what goes in the header.


Connect to the IP address and pass the Host header manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号