6

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:

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:

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
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Brad Reed
  • 443
  • 7
  • 16
  • 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` 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. – GAEfan Jun 08 '14 at 15:27
  • @GAEfan you sir are a genius - that fixed the CSS issue. However the images and fonts have different files in them. Eg, the images folder has jpeg and PNGs - so how can I specify multiple mime types? – Brad Reed Jun 08 '14 at 15:30
  • I changed to answer, so I could better format the code – GAEfan Jun 08 '14 at 15:41

7 Answers7

11

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">
GAEfan
  • 11,244
  • 2
  • 17
  • 33
  • Thanks mate. Do you think I should create an issue in the bug tracker for GAE launcher? – Brad Reed Jun 08 '14 at 17:49
  • Yes. At least someone can point to the solution if it is not a bug. – GAEfan Jun 08 '14 at 18:05
  • Same problem here, right after the update of the launcher. I think it's a brand new bug. – stenci Jun 09 '14 at 04:28
  • 1
    This workaround works for the static files of my app, but the admin server (--admin_port=xxx) still fails when serving the css files. I can test my application, but the admin server has no styles. – stenci Jun 09 '14 at 04:49
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).

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.

Babak K
  • 469
  • 5
  • 13
1

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.

Curious Sam
  • 884
  • 10
  • 12
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.

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"
Brad Reed
  • 443
  • 7
  • 16
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.

Adrian
  • 1,006
  • 2
  • 9
  • 20
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!

0

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

user7610
  • 25,267
  • 15
  • 124
  • 150