“无法使用CGI处理程序启用threadsafe”

时间:2013-08-26 00:13:59

标签: python google-app-engine

我遇到了一个常见的问题。但是,通常建议的解决方案似乎在这里不起作用。在尝试运行App Engine时,我得到“无法使用CGI处理程序启用线程安全”。当然,文档太可怕了。我正在使用webapp2,所以线程安全无关紧要。

我的文件结构应该如下: backend / api / get_json.py - 这将提供所有发送到/api/*.json的HTTP请求。换句话说,后端/部分对最终用户是隐藏的。

我无法让app.yaml识别并正确加载Python文件到/backend/api/get_json.py

app.yaml文件:

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"

后端/ 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)

错误

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

1 个答案:

答案 0 :(得分:6)

它适用于我..这是我的app.yaml(我将它与helloworld示例相结合)我在localhost上启动dev_appserver时没有任何错误。你使用什么版本的appengine?我正在使用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

您需要创建

__init__.py

在后端和api文件夹中

相关问题