Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on How do I get the error message out of a requests exception?
Post
How do I get the error message out of a requests exception?
I'm trying to log error messages from Requests exceptions. Example:
try:
make_web_request()
except RequestException as ex:
logging.error(ex)
Example output:
ERROR : ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
...okay, that's technically usable, but it's ugly. It looks more like a repr than an error message. The piece of it I actually want is the 'Connection reset by peer'. In this case I've found that I can get it with log.error(ex.args[0].args[-1])
, but I don't think I can count on that working for other subtypes of RequestException (or even other instances of the same type).
Is there a Right Way to do this?
1 comment thread