Mattman85208
Mattman85208

Reputation: 2090

Selenium Python: traceback.format_exc() error

Selenium Python: traceback.format_exc() error: (Sorry, I'm new to Python, struggling with object and method stuff)

Here is the commandline error:

Line ## in LogErrorDetials
LogErrorMessage = LogErrorMessage + "\n\n" + traceback.format_exc()
  File "C:\Python34\lib\traceback.py", line 256, in format_exc
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
  File "C:\Python34\lib\traceback.py", line 181, in format_exception
return list(_format_exception_iter(etype, value, tb, limit, chain))
  File "C:\Python34\lib\traceback.py", line 146, in _format_exception_iter
for value, tb in values:
  File "C:\Python34\lib\traceback.py", line 125, in _iter_chain
context = exc.__context__

AttributeError: 'NoneType' object has no attribute '__context__'

The offending line:

LogErrorMessage = LogErrorMessage + "\n\n" + traceback.format_exc()

How can I check that the traceback.format_exc() will work before calling it, or how can I check the attribute __context__ is not NoneType (if that is better)?

Upvotes: 0

Views: 2617

Answers (1)

Anand S Kumar
Anand S Kumar

Reputation: 90889

This seems like - Issue 23003 . It says -

This regression was introduced in Python 3.0.

I think this is fixed in Python 3.4 (According to the issue page) . I do not see any workarounds specified there.

You can try using sys.exc_info() to get the exception and then pass that into traceback.format_exception() -

a = sys.exc_info()
traceback.format_exception(*a)

Please note, traceback.format_exception() returns a list, to convert it into a string, use -

''.join(traceback.format_exception(*a))

Upvotes: 2

Related Questions