Hi,<br><br>I wish to send a request without 'Accept-Encoding: gzip, deflate' in the request header. Under Linux, this is not a problem, I got 'Accept-Encoding: identity' by default.<br><br>However, under Windows (XP SP3 with Python 2.5), no matter what I try, I always got 'Accept-Encoding: gzip, deflate' in the request header. There is no method in urllib2 to remove or disable the sending of a header. So what I can do is try to override the miraculously added header, like:<br>
<br>>>> opener = urllib2.build_opener()<br>>>> opener.addheaders = [('Accept-encoding', 'identity;q=1.0, gzip;q=0')]<br>>>> opener.open('some test url')<br><br clear="all">
or<br><br>>>> request = urllib2.Request('<a href="http://www.homemaster.cn">http://www.homemaster.cn</a>', headers={'Accept-encoding': 'identity'})<br>>>> urllib2.urlopen(request)<br>
<br>But I always still get the annoying 'gzip, deflate' in the header (captured by Wireshark). And in the latter case, it seems my 'Accept-encoding': 'identity' is changed into '---------------: --------', presumably because it clashes with the system generated header of 'gzip, deflate':<br>
<br>GET / HTTP/1.1<br>Accept-Encoding: gzip, deflate<br>Host: <a href="http://www.homemaster.cn">www.homemaster.cn</a><br>User-Agent: Python-urllib/2.5<br>Connection: close<br>---------------: --------<br><br>Strangely I neither find the string 'gzip, deflate' in urllib2.py nor in httplib.py. Where does it come and how can I remove it or replace it with 'identity'?<br>
<br>-- <br>Hong Yuan<br><br>大管家网上建材超市<br>装修装潢建材一站式购物<br><a href="http://www.homemaster.cn">http://www.homemaster.cn</a><br>