python - web.py 图片和css文件500
大家讲道理
大家讲道理 2017-04-17 13:08:36
[Python讨论组]

使用了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)
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
伊谢尔伦

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

PHPz

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号