web.py 图片和css文件500


使用了StaticMiddleware ,Static目录下css和图片文件访问500错误,报错如下


 Traceback (most recent call last):
  File "D:\python 2.7.7\lib\site-packages\web\wsgiserver\__init__.py", line 1245, in communicate
    req.respond()
  File "D:\python 2.7.7\lib\site-packages\web\wsgiserver\__init__.py", line 775, in respond
    self.server.gateway(self).respond()
  File "D:\python 2.7.7\lib\site-packages\web\wsgiserver\__init__.py", line 2020, in respond
    for chunk in response:
  File "D:\python 2.7.7\lib\site-packages\web\httpserver.py", line 247, in __iter__
    self.start_response(self.status, self.headers)
  File "D:\python 2.7.7\lib\site-packages\web\httpserver.py", line 302, in xstart_response
    out = start_response(status, response_headers, *args)
  File "D:\python 2.7.7\lib\site-packages\web\wsgiserver\__init__.py", line 2058, in start_response
    raise TypeError("WSGI response header value %r is not a byte string." % v)
TypeError: WSGI response header value u'text/css' is not a byte string.

代码是参照这里:
https://github.com/the5fire/backbonejs-learning-note/blob/master/chapters/10-expand-todos-with-server.rst

后面加上了StaticMiddleware,依然无效


 from web.httpserver import StaticMiddleware
app = web.application(urls, globals())
application = app.wsgifunc(StaticMiddleware)

python web.py

風神騎士R 10 years, 4 months ago

我也是这个问题,linux下一切正常,但windows上就报这个错误,怀疑是server相关服务的问题

亚兰那一卡 answered 10 years, 4 months ago

Your Answer