马猴烧酒 发表于 2018-9-27 09:25:54

TypeError: WSGI response header value u'text/css' is not of type str.

在我的Mac电脑上运行良好,但在Windows 8 rig上使用相同的文件,在试图请求CSS文件和图像等静态文件时,日志会出现以下错误。
HTTP/1.1" 200 5454
ERROR    2014-06-08 14:42:28,431 module.py:714] Request to '/css/rootStyles.css' failed
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 710, in _handle_request
    return handler.handle(match, environ, wrapped_start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\static_files_handler.py", line 369, in handle
    return self._handle_path(full_path, environ, start_response)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\static_files_handler.py", line 182, in _handle_path
    start_response('200 OK', headers)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\module.py", line 640, in wrapped_start_response
    return start_response(status, response_headers, exc_info)
File "C:\Program Files (x86)\Google\google_appengine\lib\cherrypy\cherrypy\wsgiserver\wsgiserver2.py", line 2155, in start_response
    raise TypeError("WSGI response header value %r is not of type str." % v)
TypeError: WSGI response header value u'text/css' is not of type str.
INFO   2014-06-08 14:42:28,433 module.py:639] default: "GET /css/rootStyles.css HTTP/1.1" 500 -
My app.yml file looks like this:
application: foobarbaz
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /img
static_dir: img
- url: /font
static_dir: font
- url: /css
static_dir: css

- url: .*
script: main.app

libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest

强人锁男 发表于 2018-9-27 09:28:51

将mimetype作为python unicode字符串发送到报头中。尝试添加mime_type:“text/css”到您的- url: /css,如下所示:
- url: /css
static_dir: css
mime_type: "text/css"

德国骨科 发表于 2018-9-27 09:30:21

在Windows 8.1上使用python 2.7.7也遇到了同样的问题。我刚刚更新到python 2.7.8,看起来问题已经解决了。

污妖王 发表于 2018-9-27 09:34:35

编辑
.\google\appengine\tools\devappserver2\admin\static_file_handler.py

content_type, _ = mimetypes.guess_type(asset_path)
assert content_type, (
变成
content_type, _ = mimetypes.guess_type(asset_path)
content_type = str(content_type)
assert content_type, (

也可以尝试
在.\google\appengine\tools\devappserver2\static_file_handler.py里
将return self._url_map.mime_type变成return str(self._url_map.mime_type)

此间少年 发表于 2018-9-27 09:37:10

在google\appengine\tools\devappserver2\static_files_handler.py

需要添加 str 到 self._get_mime_type(full_path)



天使与魔鬼 发表于 2018-9-27 09:37:46

通过将python从2.7.7降级到2.7.6,我解决了这个问题。

蛋蛋超人 发表于 2018-9-27 09:39:01

我有同样的问题
'TypeError: WSGI response header value y text/css' is not a byte string'.
我看不到CSS样式,它给我状态500。我用的是python 2.7.7,我把它改成了2.7.6,一切正常!

菜鸟闯世界 发表于 2018-10-10 08:10:50

版本问题有时候很蛋疼
页: [1]
查看完整版本: TypeError: WSGI response header value u'text/css' is not of type str.