Opened 15 years ago
Closed 15 years ago
#9054 closed defect (duplicate)
Wsgi problem with unicode in headers on Win32
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | high | Milestone: | |
Component: | web frontend | Version: | 0.11.6 |
Severity: | critical | Keywords: | wsgi, mod_wsgi, cookie, headers, unicode |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Trying to set up trac on windows XP, using mod_wsgi 3.0, with Apache 2.2.14, and Python 2.6.4.
I follow the setup instructions in:
http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac
Apparently Trac works fine, but when trying to login, I get error 500, and the following lines are in the Apache Error Log:
[Fri Feb 12 13:32:05 2010] [error] [client 127.0.0.1] mod_wsgi (pid=3620): Exception occurred processing WSGI script 'C:/trac_envs/polar/trac.wsgi'., referer: http://localhost:8080/trac/polar/ACOMON/login [Fri Feb 12 13:32:05 2010] [error] [client 127.0.0.1] TypeError: expected byte string object for header value, value of type unicode found, referer: http://localhost:8080/trac/polar/ACOMON/login
Digging into the problem, I find Trac is including some cookies using unicode strings in the response headers when logging in. These are the header values:
[Fri Feb 12 10:58:41 2010] [error] Headers: [Fri Feb 12 10:58:41 2010] [error] ('Location', 'http://localhost:8080/trac/polar/ACOMON') [Fri Feb 12 10:58:41 2010] [error] ('Content-Type', 'text/plain') [Fri Feb 12 10:58:41 2010] [error] ('Content-Length', '0') [Fri Feb 12 10:58:41 2010] [error] ('Pragma', 'no-cache') [Fri Feb 12 10:58:41 2010] [error] ('Cache-control', 'no-cache') [Fri Feb 12 10:58:41 2010] [error] ('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT') [Fri Feb 12 10:58:41 2010] [error] ('Set-Cookie', u'trac_auth=3cc465674792189bff8075bb608d31c3; Path=/') [Fri Feb 12 10:58:41 2010] [error] ('Set-Cookie', u'trac_session=2288750e31713fc8e7f3db41; expires=Fri, 12-Feb-2010 09:58:41 GMT; Path=/trac/polar/ACOMON')
I manage to fix it using the following trac.wsgi script:
import sys sys.stdout = sys.stderr def _start_response(x, status, headers, exc_info = ""): #Fix Trac using unicode in header values for i in range(len(headers)): headers[i] = (headers[i][0], str(headers[i][1])) return x(status, headers, exc_info) def application(environ, start_response): import trac.web.main x = lambda status, headers, exc_info=None: _start_response(start_response, status, headers, exc_info) return trac.web.main.dispatch_request(environ, x)
Problem is in trac_auth and trac_session cookies, as they are unicode strings, which seems not supported according to WSGI standard.
Is it necessary to use UTF-8 in these headers or should it be fixed?
Attachments (0)
Change History (1)
comment:1 by , 15 years ago
Milestone: | next-major-0.1X |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Closing this as a duplicate of #9176. This ticket was first, but #9176 has a proposed fix.