This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cgitb with Py3: TypeError: 'str' does not support the buffer interface
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, r.david.murray, wrohdewald
Priority: normal Keywords:

Created on 2014-10-27 18:41 by wrohdewald, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
cgibug.py wrohdewald, 2014-10-27 18:41
Messages (4)
msg230083 - (view) Author: Wolfgang Rohdewald (wrohdewald) Date: 2014-10-27 18:41
The attached script works with Python2.7. With Python3.4, it produces

Traceback (most recent call last):
  File "/usr/lib/python3.4/cgitb.py", line 268, in __call__
    self.handle((etype, evalue, etb))
  File "cgibug.py", line 12, in handle
    cgitb.Hook.handle(self, info)
  File "/usr/lib/python3.4/cgitb.py", line 273, in handle
    self.file.write(reset())
TypeError: 'str' does not support the buffer interface

When replacing the file mode 'wb' with 'w', it produces this failure:
  File "/usr/lib/python3.4/cgitb.py", line 288, in handle
    self.file.write(doc + '\n')
TypeError: can't concat bytes to str

The script works as expected with Python2.7 with both file modes.
msg230094 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2014-10-27 19:18
html is text, so the file mode should be 'w'. 
But I don't reproduce the behavior with Python version v3.4.2.
Which version are you using exactly?
msg230098 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-27 19:38
I don't think what html is is relevant here.  Hook is going to be dealing with strings, though, so 'w' is indeed correct.

The script works fine for me as well.  (Also tested it on 3.3.2 since I had it laying around, so it's not a recent bugfix).
msg230118 - (view) Author: Wolfgang Rohdewald (wrohdewald) Date: 2014-10-28 04:30
This now works with mode 'w' and after reinstalling the packages. My Python is 3.4.0 (ubuntu).
History
Date User Action Args
2022-04-11 14:58:09adminsetgithub: 66934
2014-10-28 04:30:46wrohdewaldsetstatus: open -> closed
resolution: not a bug
messages: + msg230118
2014-10-27 19:38:59r.david.murraysetnosy: + r.david.murray
messages: + msg230098
2014-10-27 19:18:32amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg230094
2014-10-27 18:41:35wrohdewaldcreate