2016-08-20 56 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')