I want to get the Content-Length
value from the meta variable. I need to get the size of the file that I want to download. But the last line returns an error, HTTPMessage
object has no attribute getheaders
.
import urllib.request
import http.client
#----HTTP HANDLING PART----
url = "http://client.akamai.com/install/test-objects/10MB.bin"
file_name = url.split('/')[-1]
d = urllib.request.urlopen(url)
f = open(file_name, 'wb')
#----GET FILE SIZE----
meta = d.info()
print ("Download Details", meta)
file_size = int(meta.getheaders("Content-Length")[0])
response.headers['Content-Length']
works on both Python 2 and 3:You should consider using
Requests
:For Python 3, use:
instead.
Change final line to:
It looks like you are using Python 3, and have read some code / documentation for Python 2.x. It is poorly documented, but there is no
getheaders
method in Python 3, but only aget_all
method.See this bug report.
for
Content-Length
:Works with python 3.x