URLError doesn't return json body

python json url exception

24 просмотра

1 ответ

I have built a REST interface. On '400 Bad Request' it returns a json body with specific information about the error.

(Pdb) error.code

Python correctly throws a URLError with these headers

(Pdb) print(error.headers)

Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Sat, 20 Aug 2016 13:01:05 GMT
Connection: close
Content-Length: 236

There is a content of 236 char, but I cannot find a way to read the body.

I can see the extra information using DHC chrome plugin

"error_code": "00000001",
"error_message": "The json data is not in the correct json format.\r\nThe json data is not in the correct json format.\r\n'Execution Start Time' must not be empty.\r\n'Execution End Time' must not be empty.\r\n"

However, I cannot find a way in Python to read the body

Here are some of the things I have tried and what was returned.

(Pdb) len(error.read())


error.read().decode('utf-8', 'ignore')


(Pdb) error.readline()

Автор: kennD Источник Размещён: 08.11.2019 11:25

Ответы (1)

0 плюса

I found that this works the first time it is called, but does not work if called again.


Автор: kennD Размещён: 22.08.2016 03:55
Вопросы из категории :