Reputation: 6494
How do I access the error stream using the Python requests
library? For example, using HttpURLConnection
in Java, I would do something like:
InputStream errorStream = conn.getErrorStream();
Is there a function like this with requests
?
I'm looking for the error message in the response that was supplied by the source, NOT the error status e.g. Internal Server Error
Upvotes: 1
Views: 1013
Reputation: 15376
requests
won't raise an exception if HTTP error occurs, but you can get the error message in the response content. Example:
url = 'https://stackoverflow.com/does_not_exist'
r = requests.get(url)
print(r.status_code, r.reason)
print(r.text)
Upvotes: 1