Edgewall Software
Modify

Opened 15 years ago

Closed 15 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 Andre Loker, 15 years ago

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

comment:2 by Remy Blank, 15 years ago

Component: generalweb frontend
Milestone: 0.11.5
Owner: set to Remy Blank

I'll have a look. Thanks for the report.

comment:3 by Remy Blank, 15 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  
    296296
    297297        start_response('401 Unauthorized',
    298298                       [('WWW-Authenticate', 'Basic realm="%s"' % self.realm),
    299                         ('Content-Length', 0)])('')
     299                        ('Content-Length', '0')])('')
    300300
    301301
    302302class DigestAuthentication(PasswordFileAuthentication):
     
    352352                       [('WWW-Authenticate',
    353353                        'Digest realm="%s", nonce="%s", qop="auth", stale="%s"'
    354354                        % (self.realm, nonce, stale)),
    355                         ('Content-Length', 0)])('')
     355                        ('Content-Length', '0')])('')
    356356
    357357    def do_auth(self, environ, start_response):
    358358        header = environ.get('HTTP_AUTHORIZATION')
  • trac/web/main.py

    diff --git a/trac/web/main.py b/trac/web/main.py
    a b  
    377377                errmsg = 'Environment not found'
    378378                start_response('404 Not Found',
    379379                               [('Content-Type', 'text/plain'),
    380                                 ('Content-Length', len(errmsg))])
     380                                ('Content-Length', str(len(errmsg)))])
    381381                return [errmsg]
    382382
    383383    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 Remy Blank, 15 years ago

Resolution: fixed
Status: newclosed

Patch applied in [8358], thanks!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.