I’m using
data=urllib2.urlopen(url).read()
I want to know:
-
How can I tell if the data at a URL is gzipped?
-
Does urllib2 automatically uncompress the data if it is gzipped? Will the data always be a string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This checks if the content is gzipped and decompresses it:
No. The urllib2 doesn’t automatically uncompress the data because the ‘Accept-Encoding’ header is not set by the urllib2 but by you using:
request.add_header('Accept-Encoding','gzip, deflate')