Google App Engine: Won't serve static assets with below error:

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:

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

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:

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

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

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

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.


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

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

to

content_type, _ = mimetypes.guess_type(asset_path)
content_type = str(content_type)
assert 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

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


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.

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"