290
291
return code, response.handle_response(abspath, code, msg, data)
293
def _raise_curl_http_error(self, curl, info=None):
294
def _raise_curl_http_error(self, curl, info=None, body=None):
295
"""Common curl->bzrlib error translation.
297
Some methods may choose to override this for particular cases.
299
The URL and code are automatically included as appropriate.
301
:param info: Extra information to include in the message.
302
:param body: File-like object from which the body of the page can be read.
294
304
code = curl.getinfo(pycurl.HTTP_CODE)
295
305
url = curl.getinfo(pycurl.EFFECTIVE_URL)
296
# Some error codes can be handled the same way for all
307
response_body = body.read()
308
plaintext_body = unhtml_roughly(response_body)
299
313
raise errors.TransportError(
300
314
'Server refuses to fulfill the request (403 Forbidden)'
315
' for %s: %s' % (url, plaintext_body))
306
320
msg = ': ' + info
307
321
raise errors.InvalidHttpResponse(
308
url, 'Unable to handle http code %d%s' % (code,msg))
322
url, 'Unable to handle http code %d%s: %s'
323
% (code, msg, plaintext_body))
310
325
def _debug_cb(self, kind, text):
311
326
if kind in (pycurl.INFOTYPE_HEADER_IN, pycurl.INFOTYPE_DATA_IN,