google-app-engine - Google App Engine 上的错误 Python 2.7 - 无法使用 CGI 处理程序启用 Threadsafe

标签 google-app-engine python-2.7

我曾尝试从 Python 2.5 迁移到 Python 2.7,但每次都出现相同的错误。

我在 Python 2.5 中使用 app.yaml 文件和一个脚本 main.py 做了一个非常简单的测试,它工作正常。脚本只是一个 Hello World 类型来检查一切工作正常。

应用.yaml

application: sparepartsfinder
version: 1
runtime: python
api_version: 1


handlers:

- url: /blog
  script: main.py

- url: /blog/new_entry
  script: main.py 

主要.py

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

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

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/blog', MainPage),
                                      ('/blog/new_entry',MainPage),
                                      ('/blog/archive/.*',MainPage)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

当我更改为 Python 2.7 时,我遵循 Google App Engine 上的文档在 app.yaml 和 main.py 脚本中进行更改的字母。

应用.yaml

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


handlers:

- url: /blog
  script: main.py

- url: /blog/new_entry
  script: main.py 

- url: /blog/archive/.*
  script: main.py


- url: .*
  script: main.py

主要.py

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.out.write('Hello prueba!')

app = webapp2.WSGIApplication([('/', MainPage),
                               ('/blog', MainPage),
                               ('/blog/new_entry',MainPage),
                               ('/blog/archive/.*',MainPage)],
                              debug=True)

不幸的是,它在本地或当我尝试将新配置上传到 Google App Engine 时都不起作用。 (我总是犯同样的错误)。

我可能明白我的机器(我有 Python 2.5 和 2.7)在 Windows XP 上的问题,但在我上传时却不是。

这是错误:

2012-05-04 13:02:07 Running command: "[u'C:\Python25\python2.5.exe', '-u', 'C:\Archivos >de programa\Google\google_appengine\appcfg.py', '--no_cookies', u'--email=salvador.sanjuan@gmail.com', '--passin', 'update', 'C:\Documents and Settings\SSanjuan\Mis documentos\Dropbox\Dropbox\Python\SpareParts']" Error parsing yaml file: Invalid object: threadsafe cannot be enabled with CGI handler: main.py in "C:\Documents and Settings\SSanjuan\Mis documentos\Dropbox\Dropbox\Python\SpareParts\app.yaml", line 27, column 1 2012-05-04 13:02:31 (Process exited with code 1)

最佳答案

在您的 app.yaml 中使用 main.application 而不是 main.py。您需要前者才能将 threadsafe 设置为 true

关于google-app-engine - Google App Engine 上的错误 Python 2.7 - 无法使用 CGI 处理程序启用 Threadsafe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10447879/

相关文章:

google-app-engine - 请帮助我理解 GAE 数据存储中的实体层次结构

google-app-engine - 在 GAE 中使用 gcloud-python

python-2.7 - PyInstaller 无法处理简单的 HelloWorld 程序

google-app-engine - Google App Engine 大文件上传

google-app-engine - GAE : Enabling Edge Cache with webapp2 (Python)

python - 将数据库名称插入Sqlite3命令中

python - Tensorflow - 从 int 转换为 float 奇怪的行为

python - 如何用自定义 __len__() 过程替换类 @property 的 len(..) 返回值?

google-app-engine - 应用引擎 : restrictions on the Datastore Entities `kind` value?

python-2.7 - scikit learn 随机森林给出了相对较差的预测