Google App Engine:不会提供低于错误的静态资源:

Bra*_*eed 5 css python google-app-engine

谷歌在这种情况下是无用的,似乎我是第一个遇到这个错误:/在我的Mac上工作正常,但在Windows 8装备上使用相同的文件在尝试请求静态资产(如CSS)时会在日志中出现以下错误文件和图像.以下是错误的片段:

INFO     2014-06-08 14:42:28,431 module.py:639] default: "GET /css/rootStyles.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 -
Run Code Online (Sandbox Code Playgroud)

我的app.yml文件如下所示:

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
Run Code Online (Sandbox Code Playgroud)

GAE*_*fan 10

奇怪的.另一个人昨天在Windows上有静态文件500错误.这可能是GAE错误,其中mimetype猜测作为标头中的python unicode字符串发送.尝试添加mime_type: "text/css"到您的- url: /css,如下:

- url: /css
  static_dir: css
  mime_type: "text/css"
Run Code Online (Sandbox Code Playgroud)

在app.yaml.我认为这不会解决问题,但有助于诊断.您很可能会在img和字体标题上出现另一个错误.

您可以为其他人使用通配符映射:

- url: /img/(.*\.gif)$
  static_files: img/\1
  upload: img/.*\.gif$
  mime_type: "image/gif"

- url: /img/(.*\.png)$
  static_files: img/\1
  upload: img/.*\.png$
  mime_type: "image/x-png"

- url: /img/(.*\.jpg)$
  static_files: img/\1
  upload: img/.*\.jpg$
  mime_type: "image/jpeg"
Run Code Online (Sandbox Code Playgroud)

和类似的字体.就像我说的,这可能只是GAE for Windows中的一个错误的补丁.我不完全理解请求和响应之间的握手,但您可以尝试将以下内容添加为<meta>模板中的第一个标记,以查看是否可以改善通信:

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta charset="UTF-8">
Run Code Online (Sandbox Code Playgroud)


Bra*_*eed 1

在 GAE 的问题跟踪器中启动了一个错误。请参阅此处: https: //code.google.com/p/googleappengine/issues/detail ?id=11001 同时,该线程上的 comme #4 中的临时补丁有效。

google\appengine\tools\devappserver2\static_files_handler.py

line 166, 167, 168, need add str to self._get_mime_type(full_path)

if user_headers.Get('Content-type') is None:
    #headers.append(('Content-type', self._get_mime_type(full_path)))<br />
    headers.append(('Content-type', str(self._get_mime_type(full_path))))<br /><br />
    # 2014-06-09 fix on Win7 "TypeError: WSGI response header value u'text/html' is not of type str"
Run Code Online (Sandbox Code Playgroud)