Author jmlp
Recipients jmlp
Date 2018-05-27.23:03:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1527462202.39.0.682650639539.issue33663@psf.upfronthosting.co.za>
In-reply-to
Content
When running the built-in web server of web.py, the following error messages appear when the HTTP client fetches a non existing CSS file:

TypeError('WSGI response header value 469 is not of type str.',)
Traceback (most recent call last):
  File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 1089, in communicate
    req.respond()
  File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 877, in respond
    self.server.gateway(self).respond()
  File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 1982, in respond
    for chunk in response:
  File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/httpserver.py", line 267, in __iter__
    self.start_response(self.status, self.headers)
  File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/httpserver.py", line 320, in xstart_response
    out = start_response(status, response_headers, *args)
  File "/home/jm/miniconda3/envs/REST/lib/python3.6/site-packages/web/wsgiserver/wsgiserver3.py", line 2029, in start_response
    "WSGI response header value %r is not of type str." % v)
TypeError: WSGI response header value 469 is not of type str.

The faulty header is added by Python library, http/server.py. 
Error added in version 3.4 according to comments.

Lines 467-471 in the attached file:
            body = content.encode('UTF-8', 'replace')
            self.send_header("Content-Type", self.error_content_type)
            self.send_header('Content-Length', int(len(body)))
        self.end_headers()

The value for 'Content-Length' is passed as an 'int', but only a 'str' is acceptable.

In the latest revision of 'server.py', the same code appears line 453.
A possible correction is :

            body = content.encode('UTF-8', 'replace')
            self.send_header("Content-Type", self.error_content_type)
            self.send_header('Content-Length', str(int(len(body))))
        self.end_headers()
History
Date User Action Args
2018-05-27 23:03:27jmlpsetrecipients: + jmlp
2018-05-27 23:03:22jmlpsetmessageid: <1527462202.39.0.682650639539.issue33663@psf.upfronthosting.co.za>
2018-05-27 23:03:22jmlplinkissue33663 messages
2018-05-27 23:03:22jmlpcreate