1 | import json |
||
2 | from typing import Union |
||
3 | |||
4 | import flask |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
5 | import log |
||
6 | |||
7 | |||
8 | def load(response: flask.Response) -> (int, Union[dict, str]): |
||
9 | """Convert a response's binary data (JSON) to a dictionary.""" |
||
10 | text = response.data.decode('utf-8') |
||
11 | |||
12 | if text: |
||
13 | try: |
||
14 | data = json.loads(text) |
||
15 | except json.decoder.JSONDecodeError: |
||
16 | data = text |
||
17 | else: |
||
18 | data = None |
||
19 | |||
20 | log.debug("Response: %r", data) |
||
21 | |||
22 | return response.status_code, data |
||
23 |