-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Closed
Description
I'm unable to get content-length reliably with the requests library whereas urllib2 seems to retrieve the data consistently. Not sure if additional code is required or if the URL I'm hitting is problematic.
Run this script and compare the results. I consistently get None from requests. Using the other test_url I consistently get a result from both. What am I missing?
# Test which demonstrates issues with requests get of content-length header
# This URL seems problematic (it's a several minute download)
test_url = "http://standards-oui.ieee.org/oui.txt"
# test_url = 'https://github.com/kennethreitz/requests/tarball/master'
def requests_getlen(url):
import requests
r = requests.get(url, stream=True)
return str(r.headers.get('content-length'))
def urllib_getlen(url):
import urllib2
req = urllib2.urlopen(url)
return str(req.info().getheader('content-length'))
print 'requests content-length: ' + requests_getlen(test_url)
print 'urllib2 content-length: ' + urllib_getlen(test_url)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels