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

时间:2022-04-14 00:23:46

Google is useless in this case, it seems I am the first to encounter this error :/ Works fine on my Mac, but using the same files on a Windows 8 rig gives the following error in the logs when trying to request static assets like CSS files and images. Here is a snippet of the error:

谷歌在这种情况下是没用的,似乎我是第一个遇到这个错误:/在我的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 -

My app.yml file looks like this:

我的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

7 个解决方案

#1


10  

Weird. Another person had a static files 500 error on Windows yesterday. This may be a GAE bug, where the mimetype guess is sent as a python unicode string in the header. Try adding mime_type: "text/css" to your - url: /css, as follows:

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

- url: /css
  static_dir: css
  mime_type: "text/css"

in app.yaml. I don't think this will solve the problem, but will help diagnose. You will most likely get another error on the img and font headers.

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

You can use wildcard mapping for the others:

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

- 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"

and similar for fonts. Like I said, this may just be a patch to a bug in GAE for Windows. I don't fully understand the handshake between the request and response, but you could experiment with adding the following as the first <meta> tags in your template, to see if that improves the communication:

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

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta charset="UTF-8">

#2


3  

I had the same issues using GAE SDK 1.9.6 on Windows 8.1 using python 2.7.7 (I only use the python version and haven't experienced this using Go SDK).

我在使用python 2.7.7的Windows 8.1上使用GAE SDK 1.9.6时遇到了同样的问题(我只使用python版本并且没有使用Go SDK体验过这个问题)。

I just updated to python 2.7.8 and it seems that the issues are resolved.

我刚刚更新到python 2.7.8,似乎问题已经解决。

Just wanted to share this out here, and see if other's can confirm this. I've also added this result to the bug that @Bradley had filed. Hope this helps.

只是想在这里分享一下,看看其他人是否可以证实这一点。我还将此结果添加到@Bradley提交的错误中。希望这可以帮助。

#3


1  

As a workaround I edited .\google\appengine\tools\devappserver2\admin\static_file_handler.py at

作为一种解决方法,我编辑了。\ google \ appengine \ tools \ devappserver2 \ admin \ static_file_handler.py at

content_type, _ = mimetypes.guess_type(asset_path)
assert content_type, (

content_type,_ = mimetypes.guess_type(asset_path)断言content_type,(

to

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

content_type,_ = mimetypes.guess_type(asset_path)content_type = str(content_type)断言content_type,(

of course with appropiate indentation

当然有合适的缩进

This is just for admin console.
You could also try it on
.\google\appengine\tools\devappserver2\static_file_handler.py

这仅适用于管理控制台。您也可以尝试。\ google \ appengine \ tools \ devappserver2 \ static_file_handler.py

from
return self._url_map.mime_type
to
return str(self._url_map.mime_type)
I guess but I haven't really try that.

从返回self._url_map.mime_type返回str(self._url_map.mime_type)我想但我还没有真正尝试过。

#4


1  

Started a bug in the issue tracker for GAE. See here: https://code.google.com/p/googleappengine/issues/detail?id=11001 In the meantime, the temporary patch in comme #4 on that thread works.

在GAE的问题跟踪器中启动了一个错误。请参阅此处:https://code.google.com/p/googleappengine/issues/detail?id = 11001与此同时,该线程中的#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"

#5


0  

I got rid of this problem by downgrading python from 2.7.7 to 2.7.6. Maybe you guys will be able to spot the change that caused this behavior in the 2.7.7 release notes.

我通过将python从2.7.7降级到2.7.6来解决这个问题。也许你们能够在2.7.7发行说明中发现导致这种行为的变化。

#6


0  

I had the same issue 'TypeError: WSGI response header value y text/css' is not a byte string'. I could not see CSS style, it gives me status 500. I was using python 2.7.7 and I change it to 2.7.6 and all works fine!

我有同样的问题'TypeError:WSGI响应头值y text / css'不是字节字符串'。我看不到CSS样式,它给我状态500.我使用python 2.7.7并将其更改为2.7.6并且一切正常!

#7


0  

Error 500 (without further elaboration; no tracebacks or whatever) is also reported if your /var is full.

如果你的/ var已满,也会报告错误500(没有进一步详细说明;没有追溯或其他)。

#1


10  

Weird. Another person had a static files 500 error on Windows yesterday. This may be a GAE bug, where the mimetype guess is sent as a python unicode string in the header. Try adding mime_type: "text/css" to your - url: /css, as follows:

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

- url: /css
  static_dir: css
  mime_type: "text/css"

in app.yaml. I don't think this will solve the problem, but will help diagnose. You will most likely get another error on the img and font headers.

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

You can use wildcard mapping for the others:

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

- 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"

and similar for fonts. Like I said, this may just be a patch to a bug in GAE for Windows. I don't fully understand the handshake between the request and response, but you could experiment with adding the following as the first <meta> tags in your template, to see if that improves the communication:

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

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta charset="UTF-8">

#2


3  

I had the same issues using GAE SDK 1.9.6 on Windows 8.1 using python 2.7.7 (I only use the python version and haven't experienced this using Go SDK).

我在使用python 2.7.7的Windows 8.1上使用GAE SDK 1.9.6时遇到了同样的问题(我只使用python版本并且没有使用Go SDK体验过这个问题)。

I just updated to python 2.7.8 and it seems that the issues are resolved.

我刚刚更新到python 2.7.8,似乎问题已经解决。

Just wanted to share this out here, and see if other's can confirm this. I've also added this result to the bug that @Bradley had filed. Hope this helps.

只是想在这里分享一下,看看其他人是否可以证实这一点。我还将此结果添加到@Bradley提交的错误中。希望这可以帮助。

#3


1  

As a workaround I edited .\google\appengine\tools\devappserver2\admin\static_file_handler.py at

作为一种解决方法,我编辑了。\ google \ appengine \ tools \ devappserver2 \ admin \ static_file_handler.py at

content_type, _ = mimetypes.guess_type(asset_path)
assert content_type, (

content_type,_ = mimetypes.guess_type(asset_path)断言content_type,(

to

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

content_type,_ = mimetypes.guess_type(asset_path)content_type = str(content_type)断言content_type,(

of course with appropiate indentation

当然有合适的缩进

This is just for admin console.
You could also try it on
.\google\appengine\tools\devappserver2\static_file_handler.py

这仅适用于管理控制台。您也可以尝试。\ google \ appengine \ tools \ devappserver2 \ static_file_handler.py

from
return self._url_map.mime_type
to
return str(self._url_map.mime_type)
I guess but I haven't really try that.

从返回self._url_map.mime_type返回str(self._url_map.mime_type)我想但我还没有真正尝试过。

#4


1  

Started a bug in the issue tracker for GAE. See here: https://code.google.com/p/googleappengine/issues/detail?id=11001 In the meantime, the temporary patch in comme #4 on that thread works.

在GAE的问题跟踪器中启动了一个错误。请参阅此处:https://code.google.com/p/googleappengine/issues/detail?id = 11001与此同时,该线程中的#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"

#5


0  

I got rid of this problem by downgrading python from 2.7.7 to 2.7.6. Maybe you guys will be able to spot the change that caused this behavior in the 2.7.7 release notes.

我通过将python从2.7.7降级到2.7.6来解决这个问题。也许你们能够在2.7.7发行说明中发现导致这种行为的变化。

#6


0  

I had the same issue 'TypeError: WSGI response header value y text/css' is not a byte string'. I could not see CSS style, it gives me status 500. I was using python 2.7.7 and I change it to 2.7.6 and all works fine!

我有同样的问题'TypeError:WSGI响应头值y text / css'不是字节字符串'。我看不到CSS样式,它给我状态500.我使用python 2.7.7并将其更改为2.7.6并且一切正常!

#7


0  

Error 500 (without further elaboration; no tracebacks or whatever) is also reported if your /var is full.

如果你的/ var已满,也会报告错误500(没有进一步详细说明;没有追溯或其他)。