Edgewall Software

#13575 closed defect (fixed)

Blank page in CGI mode — at Version 4

Reported by: ebourg@… Owned by: Jun Omae
Priority: normal Milestone: 1.6
Component: web frontend Version: 1.5.4
Severity: major Keywords: cgi
Cc: Branch:
Release Notes:

Write data as binary to stdout in CGI frontend.

API Changes:
Internal Changes:

Description

I've upgraded a Trac instance deployed on Apache in CGI mode. The database upgrade went well, testing in standalone mode looked ok, but with Apache I just got a blank page, no HTTP error, no stacktrace, and nothing in the Apache error.log in debug mode.

I tracked down the issue to cgi_frontend.py where an exception occurs (but isn't propagated for some reason) when calling sys.stdout.write(data):

write() argument must be str, not bytes

Converting the bytes to string fixed the issue:

sys.stdout.write(data.decode('UTF-8'))

Change History (4)

comment:1 by anonymous, 14 months ago

Actually it fixed only the rendering of the HTML pages, it broke the images.

comment:2 by anonymous, 14 months ago

This seems to work better:

sys.stdout.buffer.write(data)

comment:3 by Jun Omae, 14 months ago

Keywords: cgi added
Milestone: 1.6
Owner: set to Jun Omae
Status: newassigned

Thanks for the report. Reproduced it by the following:

$ TRAC_ENV=/var/trac/1.5-sqlite \
> SERVER_PROTOCOL=HTTP/1.0
> SERVER_PORT=3000 \
> SERVER_NAME=127.0.0.1 \
> REQUEST_METHOD=GET \
> PATH_INFO=/chrome/common/trac.ico \
> /venv/trac/1.5.4/bin/python -m trac.web.cgi_frontend
Status: 200 Ok
Content-Type: image/x-icon
Content-Length: 3638
Last-Modified: Mon, 20 Feb 2023 02:34:22 GMT
Set-Cookie: trac_session=da00d9c1ae3bde3ef228a048; expires=Wed, 07 Jun 2023 10:09:00 GMT; HttpOnly; Path=/

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/venv/trac/1.5.4/lib/python3.9/site-packages/trac/web/cgi_frontend.py", line 71, in run
    gateway.run(dispatch_request)
  File "/venv/trac/1.5.4/lib/python3.9/site-packages/trac/web/wsgi.py", line 125, in run
    self._write(chunk)
  File "/venv/trac/1.5.4/lib/python3.9/site-packages/trac/web/cgi_frontend.py", line 49, in _write
    sys.stdout.write(data)
TypeError: write() argument must be str, not bytes

comment:4 by Jun Omae, 14 months ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Fixed in [17686].

Note: See TracTickets for help on using tickets.