Search code examples
pythonhttp-headersgzipurlopen

How do i set a header that prevents the site from sending a gzip encoded response


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


Solution

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

    Accept: text/plain
    

    if you like this :)