Edgewall Software
Modify

Ticket #8475 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

AssertionError: Value of header "Content-Length" must be a string

Reported by: Andre Loker Owned by: rblank
Priority: normal Milestone: 0.11.5
Component: web frontend Version: 0.11.5rc2
Severity: critical Keywords:
Cc:
Release Notes:
API 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

Change History

comment:1 Changed 3 years ago by Andre Loker

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

comment:2 Changed 3 years ago by rblank

  • Component changed from general to web frontend
  • Milestone set to 0.11.5
  • Owner set to rblank

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

comment:3 Changed 3 years ago by rblank

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 Changed 3 years ago by rblank

  • Resolution set to fixed
  • Status changed from new to closed

Patch applied in [8358], thanks!

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from rblank. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.