Google App Engine上的Python 2.7错误 - 无法使用CGI处理程序启用Threadsafe [英] Error Python 2.7 on Google App Engine - Threadsafe cannot be enabled with CGI handler

查看:160
本文介绍了Google App Engine上的Python 2.7错误 - 无法使用CGI处理程序启用Threadsafe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Python 2.5迁移到Python 2.7,但每次都收到相同的错误。



我在Python 2.5中做了一个非常简单的测试, app.yaml文件和一个脚本main.py,它工作正常。



app.yaml

这个脚本只是一个Hello World类型来检查everythin。 应用程序:sparepartsfinder 
版本:1
运行库:python
api_version:1


处理程序:

- url:/ blog
script:main.py

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

main.py

  from google.appengine .ext import webapp $ b $ from google.appengine.ext.webapp.util import run_wsgi_app 
$ b 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(应用程序)

if __name__ ==__main__:
main()

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



app.yaml

 应用程序:sparepartsfinder 
版本:1
运行时:python27
api_version:1
线程安全:true


处理程序:
$ b $ - url:/ blog
脚本:main.py

- url:/ blog / new_entry
脚本:main.py

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


- url:。*
script:main.py

main.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)

WOR k在本地或当我尝试将新配置上传到Google App Engine时。 (我总是犯同样的错误)。

我可以在Windows XP上理解我的机器中的问题(我有Python 2.5和2.7),但是当我上传。

这是错误:


2012-05-04 13 :02:07运行命令:[u'C:\Python25\python2.5.exe','-u','C:\Archivos> deprograma\Google\google_appengine\appcfg.py ','--no_cookies',u'--电子邮件= salvador.sanjuan@gmail.com',' - passin','更新','C:\ Documents and Settings \SSanjuan\Misi documentos\ Dropbox \Dropbox\Python\SpareParts']
分析yaml文件时出错:
无效对象:
无法使用CGI处理程序启用threadsafe:main.py
in C:\ Documents and Settings \SSanjuan\Missengeros\Dropbox\Dropbox\Python\SpareParts\app.yaml,第27行,第1列
2012-05-04 13:02 :31(用代码1退出进程)


解决方案使用 main.application 代替 main。 py 在你的app.yaml中。您需要前者以将 threadsafe 设置为 true


I have tried to move to Python 2.7 from Python 2.5 but I keep getting the same error everytime.

I have made a very simple test in Python 2.5 working with the app.yaml file and just one script main.py and it works fine. The script it just a Hello World type to check everythin works fine.

app.yaml

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


handlers:

- url: /blog
  script: main.py

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

main.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()

When I change to Python 2.7 I follow the documents on the Google App Engine to the letter making the changes in both the app.yaml and main.py script.

app.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

main.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)

Unfortunately it doesn't work either in local or when I try to upload the new configuration to the Google App Engine. ( I get always the same mistake).

I may understand the problem in my machine ( I have both Python 2.5 and 2.7 ) on a Windows XP, but not when I upload.

This is the error:

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)

解决方案

Use main.application instead of main.py in your app.yaml. You need the former in order to set threadsafe to true.

这篇关于Google App Engine上的Python 2.7错误 - 无法使用CGI处理程序启用Threadsafe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆