Ensure the msg property of HttpResponseException is a string. (#7979)

This commit is contained in:
Patrick Cloke 2020-07-29 13:56:06 -04:00 committed by GitHub
parent d90087cffa
commit a53e0160a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View file

@ -395,7 +395,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300:
return json.loads(body.decode("utf-8"))
else:
raise HttpResponseException(response.code, response.phrase, body)
raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
@defer.inlineCallbacks
def post_json_get_json(self, uri, post_json, headers=None):
@ -436,7 +438,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300:
return json.loads(body.decode("utf-8"))
else:
raise HttpResponseException(response.code, response.phrase, body)
raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
@defer.inlineCallbacks
def get_json(self, uri, args={}, headers=None):
@ -509,7 +513,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300:
return json.loads(body.decode("utf-8"))
else:
raise HttpResponseException(response.code, response.phrase, body)
raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
@defer.inlineCallbacks
def get_raw(self, uri, args={}, headers=None):
@ -544,7 +550,9 @@ class SimpleHttpClient(object):
if 200 <= response.code < 300:
return body
else:
raise HttpResponseException(response.code, response.phrase, body)
raise HttpResponseException(
response.code, response.phrase.decode("ascii", errors="replace"), body
)
# XXX: FIXME: This is horribly copy-pasted from matrixfederationclient.
# The two should be factored out.