2

i am using python urllib2.urlopen to get html content and i am getting a gziped response.
can i set the headers so i will get it not zipped ?

my code

response = urlopen(url,None , TIMEOUT)
html = response.read()  # read html
print html

as Tichodroma suggested i try this

request = Request(url)
request.add_header('Accept-encoding', 'text/plain')
response = urlopen(request,None , TIMEOUT)
html = response.read().lower()  # read html
print html

now it is working

yossi
  • 12,945
  • 28
  • 84
  • 110
  • Exact duplicate of http://stackoverflow.com/questions/3947120/dose-python-urllib2-will-automaticly-uncompress-gzip-data-from-fetch-webpage – Andrew Walker Feb 02 '12 at 11:47
  • 1
    no its not a duplicate - i dont want to decompress it i want to get it not zipped in the first place – yossi Feb 02 '12 at 12:37

1 Answers1

1

Set the Accept header to the mime types you want to accept.

Accept: text/plain

if you like this :)