Opened 16 years ago
Closed 16 years ago
#8475 closed defect (fixed)
AssertionError: Value of header "Content-Length" must be a string
| Reported by: | Andre Loker | Owned by: | Remy Blank |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.11.5 |
| Component: | web frontend | Version: | 0.11.5rc2 |
| Severity: | critical | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
I have tracd connected to IIS via AJP and I'm using basic authentication. When upgrading from 0.11.4 to 0.11.5rc2 whenever I try to login I get the following error:
Traceback (most recent call last):
File "C:\Tools\Python26\lib\site-packages\flup-1.0.3.dev_20090612-py2.6.egg\flup\server\ajp_base.py", line 486, in run
self._conn.server.handler(self)
File "C:\Tools\Python26\lib\site-packages\flup-1.0.3.dev_20090612-py2.6.egg\flup\server\ajp_base.py", line 898, in handler
result = self.application(environ, start_response)
File "C:\Tools\Python26\lib\site-packages\trac-0.11.5rc2-py2.6.egg\trac\web\standalone.py", line 81, in __call__
return self.application(environ, start_response)
File "C:\Tools\Python26\lib\site-packages\trac-0.11.5rc2-py2.6.egg\trac\web\standalone.py", line 54, in __call__
remote_user = auth.do_auth(environ, start_response)
File "C:\Tools\Python26\lib\site-packages\trac-0.11.5rc2-py2.6.egg\trac\web\auth.py", line 299, in do_auth
('Content-Length', 0)])('')
File "C:\Tools\Python26\lib\site-packages\flup-1.0.3.dev_20090612-py2.6.egg\flup\server\ajp_base.py", line 889, in start_response
assert type(val) is str, 'Value of header "%s" must be a string' % name
AssertionError: Value of header "Content-Length" must be a string
As a result, no-one is able to login anymore.
I was able to fix the error by changing line 299 and 355 of trac/web/auth.py (from tags/trac-0.11.5rc2) in a way that the provided content-length is a string instead of an integer:
start_response('401 Unauthorized',
[('WWW-Authenticate', 'Basic realm="%s"' % self.realm),
('Content-Length', '0')])('')
and
start_response('401 Unauthorized',
[('WWW-Authenticate',
'Digest realm="%s", nonce="%s", qop="auth", stale="%s"'
% (self.realm, nonce, stale)),
('Content-Length', '0')])('')
Hope that helps to fix the problem.
Attachments (0)
Change History (4)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
| Component: | general → web frontend |
|---|---|
| Milestone: | → 0.11.5 |
| Owner: | set to |
I'll have a look. Thanks for the report.
comment:3 by , 16 years ago
Indeed, the full patch is the following:
-
trac/web/auth.py
diff --git a/trac/web/auth.py b/trac/web/auth.py
a b 296 296 297 297 start_response('401 Unauthorized', 298 298 [('WWW-Authenticate', 'Basic realm="%s"' % self.realm), 299 ('Content-Length', 0)])('')299 ('Content-Length', '0')])('') 300 300 301 301 302 302 class DigestAuthentication(PasswordFileAuthentication): … … 352 352 [('WWW-Authenticate', 353 353 'Digest realm="%s", nonce="%s", qop="auth", stale="%s"' 354 354 % (self.realm, nonce, stale)), 355 ('Content-Length', 0)])('')355 ('Content-Length', '0')])('') 356 356 357 357 def do_auth(self, environ, start_response): 358 358 header = environ.get('HTTP_AUTHORIZATION') -
trac/web/main.py
diff --git a/trac/web/main.py b/trac/web/main.py
a b 377 377 errmsg = 'Environment not found' 378 378 start_response('404 Not Found', 379 379 [('Content-Type', 'text/plain'), 380 ('Content-Length', len(errmsg))])380 ('Content-Length', str(len(errmsg)))]) 381 381 return [errmsg] 382 382 383 383 if not env_path:
All other instances where we set the Content-Length header use req.send_header(), which converts the value to a string.
comment:4 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Patch applied in [8358], thanks!



Probably the error occurs at more places, e.g. in web/main.py when a 404 is returned.