[New-bugs-announce] [issue32669] cgitb file to print OSError exceptions

steven Michalske report at bugs.python.org
Thu Jan 25 14:03:08 EST 2018


New submission from steven Michalske <smichalske at gmail.com>:

With the source

```
import cgitb
import sys

try:
    f = open('non_exitant_file_path.foo')
except Exception as e:
    cgitb.text(sys.exc_info())
```

we get the output

```
Traceback (most recent call last):
  File "foo.py", line 22, in <module>
    f = open('non_exitant_file_path.foo')
FileNotFoundError: [Errno 2] No such file or directory: 'non_exitant_file_path.foo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo.py", line 24, in <module>
    cgitb.text(sys.exc_info())
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/cgitb.py", line 245, in text
    value = pydoc.text.repr(getattr(evalue, name))
AttributeError: characters_written
```

In bug #30554 it was brought up that there are attributes designed as invariant os some other as designed behavior.  Unfortunately it was closed "as designed" 

So this means that cgitb has a bug when text formatting a sys_exc traceback of an OSError.

This is hidden in the by the hook with this code form cgitb.py
by falling back to the standard formatter...

line 277
```
        try:
            doc = formatter(info, self.context)
        except:                         # just in case something goes wrong
            doc = ''.join(traceback.format_exception(*info))
            plain = True
```

----------
messages: 310702
nosy: hardkrash
priority: normal
severity: normal
status: open
title: cgitb file to print OSError exceptions
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32669>
_______________________________________


More information about the New-bugs-announce mailing list