I’m making a request via urllib2 that is coming back with the following headers:
>>> dict(response.info())
{'expires': 'Wed, 31 Dec 1969 19:00:00 EST, Wed, 31 Dec 1969 19:00:00 EST', 'server': 'Apache-Coyote/1.1, Apache-Coyote/1.1', 'connection': 'close', 'pragma': 'No-cache, No-cache', 'cache-control': 'no-cache, no-cache', 'date': 'Thu, 19 Jan 2012 20:16:00 GMT', 'content-type': 'audio/mpeg'}
As I understand it, since ‘connection: close’ is set, the request will keep streaming back until the remote host finishes, so no Content-Length is set. It seems like I should be able to determine the length of the content by somehow analyzing the response object, but I can’t figure out how to do it. Any suggestions?
I think you would need to call
read()on the response to read it into a string, and then calllen()on the string.