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: TypeError in wsgiref.handlers when using CGIHandler
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Add fixups for encoding problems to wsgiref
View: 10155
Assigned To: Nosy List: aclover, orsenthil, toxicdav3
Priority: normal Keywords: patch

Created on 2010-06-18 00:25 by toxicdav3, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue9022.patch aclover, 2010-10-20 15:44 Make CGIHandler use byte streams for input/outpu
Messages (3)
msg108073 - (view) Author: David (toxicdav3) Date: 2010-06-18 00:25
The following code produces a type error, but from what I can tell it does comply with PEP333. This issue appeared using Python 3.1.1 and 3.1.2 on both Windows and Ubuntu. I have only tried the 32 bit versions. Works fine in Python 2.6.5.12 but I guess thats irrelevant.

-----
def application(environ, start_response):
	start_response('200 OK',[('Content-type','text/html')])
	return ['<html><body>Hello World!</body></html>']
	
from wsgiref.handlers import CGIHandler
CGIHandler().run(application)
-----
Traceback (most recent call last):
  File "C:\Python31\lib\wsgiref\handlers.py", line 75, in run
    self.finish_response()
  File "C:\Python31\lib\wsgiref\handlers.py", line 116, in finish_response
    self.write(data)
  File "C:\Python31\lib\wsgiref\handlers.py", line 210, in write
    self.send_headers()
  File "C:\Python31\lib\wsgiref\handlers.py", line 266, in send_headers
    self.send_preamble()
  File "C:\Python31\lib\wsgiref\handlers.py", line 196, in send_preamble
    self._write('Status: %s\r\n' % self.status)
  File "C:\Python31\lib\wsgiref\handlers.py", line 402, in _write
    self.stdout.write(data)
TypeError: must be str, not bytes
-----
msg119215 - (view) Author: And Clover (aclover) * Date: 2010-10-20 15:44
Yes, CGIHandler is broken in 3.0-3.1; wsgiref in general has been in limbo until the whole issue of py3k-WSGI is sorted. This seems to be happening now in PEP 3333.

Attached patch to make CGIHandler use the byte interfaces for stdin/stdout, which allows the write calls to work and provides byte streams to the WSGI application as required by PEP 3333.
msg177666 - (view) Author: And Clover (aclover) * Date: 2012-12-17 20:27
(This issue should be closed; it is superseded by the fix for 10155 in Python 3.2.)
History
Date User Action Args
2022-04-11 14:57:02adminsetgithub: 53268
2012-12-25 15:16:34orsenthilsetstatus: open -> closed
superseder: Add fixups for encoding problems to wsgiref
resolution: duplicate
stage: resolved
2012-12-17 20:27:42acloversetmessages: + msg177666
2010-10-21 04:03:10orsenthilsetnosy: + orsenthil
2010-10-20 15:44:49acloversetfiles: + issue9022.patch

nosy: + aclover
messages: + msg119215

keywords: + patch
2010-06-18 00:25:45toxicdav3create