For some weeks the Apport retracers have started crashing as soon as they try to access an attachment of a private bug. This has started to happen independently of the data center firewall configuration (since I can reproduce it locally as well) or python-launchpadlib and dependency version bumps (since I get the same on the local checkout on ronne, which hasn't been updated in ages). It seems that this regressed in Launchpad itself, but I'm also filing it against python-launchpadlib for a potential improvement of the error message, since it is very unclear.
Simple reproducer:
$ lp-shell
>>> b=lp.bugs[614676]
>>> b.attachments[0].data
<lazr.restfulclient.resource.HostedFile object at 0x1d33a90>
>>> f = b.attachments[0].data.open()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py", line 357, in open
return HostedFileBuffer(self, mode, content_type, filename)
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/resource.py", line 953, in __init__
self.url, return_response=True)
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/_browser.py", line 287, in get
response, content = self._request(url, extra_headers=headers)
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/_browser.py", line 242, in _request
str(url), method=method, body=data, headers=headers)
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/_browser.py", line 211, in _request_and_retry
url, method=method, body=body, headers=headers)
File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 1129, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/_browser.py", line 130, in _request
redirections, cachekey)
File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 946, in _request
(response, content) = self.request(location, redirect_method, body=body, headers = headers, redirections = redirections - 1)
File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 1129, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/lib/python2.6/dist-packages/lazr/restfulclient/_browser.py", line 130, in _request
redirections, cachekey)
File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 901, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/lib/python2.6/dist-packages/httplib2/__init__.py", line 871, in _conn_request
response = conn.getresponse()
File "/usr/lib/python2.6/httplib.py", line 988, in getresponse
method=self._method)
File "/usr/lib/python2.6/httplib.py", line 330, in __init__
self.fp = sock.makefile('rb', 0)
AttributeError: 'NoneType' object has no attribute 'makefile'
This only happens on private bugs, public bugs work fine.
The problem is that HostedFile only redirects to the librarian, but this file is available through the restricted librarian so cannot be fetched direcly by the clients (for now, the fix for bug 395960 will likely change that).
HostedFile should stream the file directly when it is a restricted file.