我試圖從Python 2.5遷移到Python 2.7,但每次都收到相同的錯誤。Google App Engine上的Python 2.7錯誤 - 無法使用CGI處理程序啓用Threadsafe
我在Python 2.5中使用app.yaml文件和一個腳本main.py進行了非常簡單的測試,它工作正常。它只是一個Hello World類型來檢查everythin的腳本工作正常。
的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我按照在Google App Engine的文件,以信進行更改同時在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)
遺憾的是它不無論是在本地或當我嘗試新的配置上傳到谷歌應用程序引擎的工作。 (我總是犯同樣的錯誤)。
我可以在Windows XP上理解我的機器上的問題(我有Python 2.5和2.7),但是我沒有上傳。
這是錯誤:
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 protected]', '--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)
但是文件main.application在哪裏?如果我改變它出現新的錯誤。:找不到模塊main.app args =('Could not find module main.app',) message ='Could not find module main.app' –
user1374783
在前面的表格中, main.application'(或'main.app')應該直接用點符號指向WSGIApplication對象。你的main.py在哪裏發生BTW?如果它位於項目頂層目錄下,則可以根據該文件全局範圍內的WSGIApplication對象的名稱使用'main.app'或'main.application'中的任意一個。 –
另請參閱:https://developers.google.com/appengine/docs/python/python27/using27#Configuring_WSGI_Script_Handlers –