玩蛇网提供最新Python编程技术信息以及Python资源下载!

Python 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)

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

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

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd19606.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月24日 - 20时21分04秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules