eb80
eb80

Reputation: 4738

"threadsafe cannot be enabled with CGI handler"

I am running into what looks like a common problem. However, the solution often suggested doesn't seem to work here. I am getting "threadsafe cannot be enabled with CGI handler" when trying to run App Engine. Of course, the documentation is horrible. I am using webapp2, so the threadsafe shouldn't matter.

My file structure should be as follows: backend/api/get_json.py - This serves all HTTP requests coming to /api/*.json In other words, the backend/ section is hidden from the end user.

I am having trouble getting the app.yaml to recognize and properly load the Python file at /backend/api/get_json.py

app.yaml file:

application: ebtest
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /api/.*\.json
  script: backend/api/get_json.application

libraries:
- name: webapp2
  version: "2.5.2"

backend/api/get_json.py

import webapp2

class MainPage(webapp2.RequestHandler):

    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')


application = webapp2.WSGIApplication([
    ('/api/get_users.json', MainPage),
], debug=True)

Errors

  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
    raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: **threadsafe cannot be enabled with CGI handler: backend/api/get_json.application**

Upvotes: 3

Views: 2422

Answers (1)

marcadian
marcadian

Reputation: 2618

It works for me.. here is my app.yaml (I combined it with helloworld example) I don't get any error on starting dev_appserver on localhost. What version of appengine do you use? I'm using 1.7.5

application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: django
  version: "1.2"
- name: pycrypto
  version: "2.6"


handlers:
- url: /api/.*\.json
  script: backend.api.get_json.application
- url: /.*
  script: helloworld.app

You need to create

__init__.py

inside the backend and the api folder

Upvotes: 6

Related Questions