2016-08-20 54 views
0

我已经构建了一个REST接口。在'400错误请求'中,它返回一个带有关于错误的特定信息的json主体。URLError不返回json主体

(Pdb) error.code 
400 

Python的正常投用这些头

(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 

有236字符的内容URLError,但我不能找到一种方法来读取体。

我可以用DHC铬插件

{ 
"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" 
} 

但是看到额外的信息,我无法找到一个Python的方式来读取人体

这里有一些事情我都试过,什么是回。

(Pdb) len(error.read()) 

0 

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

'' 

(Pdb) error.readline() 

b'' 
+0

请提供您的代码,以便我们提供更多帮助。 – nir0s

回答

0

我发现这是第一次调用它,但如果再次调用不起作用。 ('utf-8')