The first time I open a binary file it works fine.
send: 'GET /beta/~leonardr/mugshot HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="63471975", oauth_timestamp="1222438065", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="5dxcwV7XbD3tSNl24DHk", oauth_signature="&Mp3Lb7rrRZ6g9zTFcj9SGh3LWFMxKvbv13QLH6LsxXvhk7kNgq0gsMtPPVbMKHw2vC9TmmCwb9bG5q7B"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: ''
send: 'GET /beta/~leonardr/mugshot HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="63471975", oauth_timestamp="1222438065", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="5dxcwV7XbD3tSNl24DHk", oauth_signature="&Mp3Lb7rrRZ6g9zTFcj9SGh3LWFMxKvbv13QLH6LsxXvhk7kNgq0gsMtPPVbMKHw2vC9TmmCwb9bG5q7B"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 303 See Other\r\n'
header: Date: Fri, 26 Sep 2008 14:07:46 GMT
header: Server: zope.server.http (HTTP)
header: X-Powered-By: Zope (www.zope.org), Python (www.python.org)
header: X-Content-Type-Warning: guessed from content
header: Content-Length: 0
header: Content-Type: text/plain
header: Location: https://staging.launchpadlibrarian.net/12619694/skull.jpg
header: Via: 1.1 wildcard.staging.launchpad.net
send: 'GET /12619694/skull.jpg HTTP/1.1\r\nHost: staging.launchpadlibrarian.net:443\r\nAccept-Encoding: identity\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="90375050", oauth_timestamp="1222438067", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="5dxcwV7XbD3tSNl24DHk", oauth_signature="&Mp3Lb7rrRZ6g9zTFcj9SGh3LWFMxKvbv13QLH6LsxXvhk7kNgq0gsMtPPVbMKHw2vC9TmmCwb9bG5q7B"\r\nte: deflate, gzip\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Sat, 26 Jul 2008 14:58:28 GMT
header: Server: TwistedWeb/8.0.1
header: Last-Modified: Wed, 12 Mar 2008 21:47:05 GMT
header: Content-Length: 29541
header: Content-Type: image/jpeg
header: X-Cache: MISS from arsenic.canonical.com
header: X-Cache-Lookup: MISS from arsenic.canonical.com:3128
header: Age: 2101
header: X-Cache: HIT from arsenic.canonical.com
header: X-Cache-Lookup: HIT from arsenic.canonical.com:3128
header: Via: 1.0 arsenic.canonical.com:3128 (squid/2.6.STABLE18), 1.0 launchpadlibrarian.net, 1.0 arsenic.canonical.com:3128 (squid/2.6.STABLE18)
header: Via: 1.1 staging.launchpadlibrarian.net
header: Cache-Control: public,max-age=604800
>>> mugshot_handle.last_modified
'Wed, 12 Mar 2008 21:47:05 GMT'
The second time, not so much.
>>> mugshot_handle = mugshot.open()
send: 'GET /beta/~leonardr/mugshot HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="06393936", oauth_timestamp="1222439543", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="5dxcwV7XbD3tSNl24DHk", oauth_signature="&Mp3Lb7rrRZ6g9zTFcj9SGh3LWFMxKvbv13QLH6LsxXvhk7kNgq0gsMtPPVbMKHw2vC9TmmCwb9bG5q7B"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: ''
send: 'GET /beta/~leonardr/mugshot HTTP/1.1\r\nHost: api.staging.launchpad.net:443\r\nAccept-Encoding: identity\r\nte: deflate, gzip\r\nAuthorization: OAuth realm="https://api.launchpad.net", oauth_nonce="06393936", oauth_timestamp="1222439543", oauth_consumer_key="just testing", oauth_signature_method="PLAINTEXT", oauth_version="1.0", oauth_token="5dxcwV7XbD3tSNl24DHk", oauth_signature="&Mp3Lb7rrRZ6g9zTFcj9SGh3LWFMxKvbv13QLH6LsxXvhk7kNgq0gsMtPPVbMKHw2vC9TmmCwb9bG5q7B"\r\naccept: application/json\r\nuser-agent: Python-httplib2/$Rev: 259 $\r\n\r\n'
reply: 'HTTP/1.1 303 See Other\r\n'
header: Date: Fri, 26 Sep 2008 14:32:24 GMT
header: Server: zope.server.http (HTTP)
header: X-Powered-By: Zope (www.zope.org), Python (www.python.org)
header: X-Content-Type-Warning: guessed from content
header: Content-Length: 0
header: Content-Type: text/plain
header: Location: https://staging.launchpadlibrarian.net/12619694/skull.jpg
header: Via: 1.1 wildcard.staging.launchpad.net
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "launchpadlib/resource.py", line 699, in open
return HostedFileBuffer(self, mode, content_type, filename)
File "launchpadlib/resource.py", line 724, in __init__
self.url, True)
File "launchpadlib/_browser.py", line 221, in get
response, content = self._request(url)
File "launchpadlib/_browser.py", line 211, in _request
raise HTTPError(response, content)
launchpadlib.errors.HTTPError: HTTP Error 304: Ok
httplib2 is supposed to return the cached request (the cache file in this case is staging.launchpadlibrarian.net,12619694,skull.jpg-application,json,201da2a36ecabc4e51fd9af2a5bc2971, and if I remove it the problem goes away), but instead it's either ignoring it or treating the 304 error code as an exception. I suspect this has something to do with the fact that the 304 error code comes after following a redirect, and not in response to the initial request.
I think I was faced with the very same bug today, but the strange thing is: I can only reproduce this with an old cache which I've been using since two month. But when I create new cache and run a script to get hosted files twice, I don't get this error.
Please see the attached log as an example:
lines 1-54: reading me.mugshot, using the old cache => reproducing this error
lines 55-75: reading me.mugshot, using "/tmp/new_cache" as cache => works fine
lines 75-80: cache is still there
lines 81-89: reading me.mugshot, using "/tmp/new_cache" as cache => cannot reproduce error
As you can see in the last few lines of the log newly created caches of binary files have "age:"-value in the header, maybe this is a reason why this is fixed.