why is the content-lenght different in case of using requests
and urlopen(url).info()
>>> url = 'http://pymotw.com/2/urllib/index.html'
>>> requests.head(url).headers.get('content-length', None)
'8176'
>>> urllib.urlopen(url).info()['content-length']
'38227'
>>> len(requests.get(url).content)
38274
I was going to make a check for size of file in bytes to split the buffer to multiple threads based on Range
in urllib2
but if I do not have the actual size of file in bytes it won't work..
only len(requests.get(url).content)
gives 38274
which is closest but still not correct and moreover it is downloading the content which i didn't wanted.
HEAD
. Or it might be that the server returns different things based on other headers sent (or not) by the respective methods (user-agent, cookies...). Try usingcurl -v url
andcurl -I
, or any other method that sends the exact same request save for theHEAD
instead of post, and check the results. – Jenson