I have an exception that looks like this:
exc = ProtocolError('Connection Aborted', BadStatusLine('No status line received'))
how can I access the No status line received part?
Here's the example situation:
def some_function():
raise ProtocolError('Connection Aborted', BadStatusLine('No status line received'))
def some_other_function():
try:
some_function()
except Exception as exc:
if exc.message:
details = exc.message
else:
details = exc
In the code above I'm trying to check if the returned exception has a message and if so I'm supposed to write it into the database, however when I call the exc.message it returns an empty string, and when I call exc it returns:
bson.errors.InvalidDocument: cannot encode object: ProtocolError('Connection Aborted', BadStatusLine('No status linereceived',)), of type: <class 'urllib3.exceptions.ProtocolError'>
so I cant write it into the database since its a type Exception not string, what I need to do is to see if the returned Exception has another nested Exception in it and get it's message.
type: <class 'urllib3.exceptions.ProtocolError'>