dc****@gmail.com wrote:
What is the correct way to download a file through HTTP and save it to
the file name suggested by "Content-Disposition"?
Perhaps something along the lines of the following?
>>url = r'http://www.4so9.com/cauca/files/ban-doc/francois/stingray/198%20lb%20stingray%201%20.JPG'
proxy = 'proxy02:8080'
import httplib
c = httplib.HTTPConnection(proxy)
c.request('GET', url)
resp = c.getresponse()
for k in resp.msg.keys():
.... print resp.msg.getallmatchingheaders(k)
....
['Content-Length: 64632\r\n']
['Proxy-Connection: close\r\n']
['X-Cache: HIT from SPSweb\r\n']
['Accept-Ranges: bytes\r\n']
['Server: Apache/2.0.51 (Fedora)\r\n']
['Last-Modified: Fri, 03 Dec 2004 16:57:30 GMT\r\n']
['ETag: "3b2375-fc78-8c13280"\r\n']
['Date: Tue, 05 Sep 2006 10:35:48 GMT\r\n']
['Content-Type: image/jpeg\r\n']
['Age: 31440\r\n']
>>data = resp.fp.read()
len(data)
64632
>>data[:100]
'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x02\x02\x00\ x00\x00\x00\x00\x00\xff\xe1\x057Exif\x00\x00II*\x0 0\x08\x00\x00\x00\t\x00\x0f\x01\x02\x00\x06\x00\x0 0\x00z\x00\x00\x00\x10\x01\x02\x00\x13\x00\x00\x00 \x80\x00\x00\x00\x12\x01\x03\x00\x01\x00\x00\x00\x 01\x00\x00\x00\x1a\x01\x05\x00\x01\x00\x00\x00\x93 \x00\x00\x00\x1b\x01\x05\x00\x01\x00\x00\x00\x9b\x 00\x00\x00'
>>resp.fp.close()