【问题标题】:"threadsafe cannot be enabled with CGI handler"“无法使用 CGI 处理程序启用线程安全”
【发布时间】:2013-08-26 00:13:58
【问题描述】:

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

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

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

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

【问题讨论】:

  • 线程安全不应该是真的而不是真的吗?我也认为您不需要在库中指定 webapp2 。至少这就是我的应用程序中的内容
  • 我认为现在我查看文档应该是正确的;不幸的是,这并不能解决问题。我在离线和上面的sn-p中更新了代码。

标签: python google-app-engine


【解决方案1】:

它对我有用.. 这是我的 app.yaml(我将它与 helloworld 示例结合使用)我在本地主机上启动 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 文件夹内

【讨论】:

  • 你能分享你的文件结构吗?我的 get_json 不在根目录中?我在 backend/api/get_json.py 有它吗?我如何做文件结构?换句话说,你有“脚本:get_json.application”,但我有 get_json 嵌套在 backend/api/get_json.py ...我如何保持我的文件结构?
  • 哦,抱歉,我不知道您需要保留结构。我改变了答案
猜你喜欢
  • 2012-07-19
  • 2012-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多