[英]How to get HTTP error stream using Python requests library?
如何使用 Python requests
庫訪問錯誤流? 例如,在 Java 中使用HttpURLConnection
,我會這樣做:
InputStream errorStream = conn.getErrorStream();
有沒有這樣的功能requests
?
我正在尋找源提供的響應中的錯誤消息,而不是錯誤狀態,例如內部服務器錯誤
如果發生 HTTP 錯誤, requests
不會引發異常,但您可以在響應內容中獲取錯誤消息。 例子:
url = 'https://stackoverflow.com/does_not_exist'
r = requests.get(url)
print(r.status_code, r.reason)
print(r.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.