mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-03 03:54:52 -04:00
Python 3: Convert some unicode/bytes uses (#3569)
This commit is contained in:
parent
c4842e16cb
commit
da7785147d
17 changed files with 122 additions and 67 deletions
|
@ -171,8 +171,16 @@ def parse_json_value_from_request(request, allow_empty_body=False):
|
|||
if not content_bytes and allow_empty_body:
|
||||
return None
|
||||
|
||||
# Decode to Unicode so that simplejson will return Unicode strings on
|
||||
# Python 2
|
||||
try:
|
||||
content = json.loads(content_bytes)
|
||||
content_unicode = content_bytes.decode('utf8')
|
||||
except UnicodeDecodeError:
|
||||
logger.warn("Unable to decode UTF-8")
|
||||
raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
|
||||
|
||||
try:
|
||||
content = json.loads(content_unicode)
|
||||
except Exception as e:
|
||||
logger.warn("Unable to parse JSON: %s", e)
|
||||
raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue