我尝试从 Python 2.5 迁移到 Python 2.7,但每次都会遇到相同的错误。
我在 Python 2.5 中使用 app.yaml 文件和一个脚本 main.py 做了一个非常简单的测试,它工作得很好。该脚本只是一个 Hello World 类型,用于检查一切是否正常。
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()
当我更改为 Python 2.7 时,我遵循谷歌应用引擎 https://developers.google.com/appengine/docs/python/python27/using27#Configuring_the_Application在 app.yaml 和 main.py 脚本中进行更改。
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)
不幸的是,它在本地或当我尝试将新配置上传到 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 >de programa\Google\google_appengine\appcfg.py ', '--no_cookies', u'[电子邮件受保护] /cdn-cgi/l/email-protection', '--passin', '更新', 'C:\Documents and Settings\SSanjuan\Mis documentos\Dropbox\Dropbox\Python\SpareParts']"
解析yaml文件时出错:
无效对象:
无法使用 CGI 处理程序启用线程安全:main.py
在“C:\Documents and Settings\SSanjuan\Mis documentos\Dropbox\Dropbox\Python\SpareParts\app.yaml”中,第 27 行,第 1 列
2012-05-04 13:02:31(进程退出,代码为 1)