web.py 图片和css文件500

fishenal
  • 3.4k

使用了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)
回复
阅读 7k
2 个回答

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

柠檬园主
  • 5
新手上路,请多包涵

极力不推荐使用web.py自带的server来跑,除非你是跑本地测试。
使用nginx或apache都可以把静态文件单独处理,而不需要web.py来操心。
就算是本地跑web.py自带的server,按照官方文档的cookbook那样简单设置一下也没问题,用不着用middleware

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏