2013-07-07 45 views
10

我在下面https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction谷歌應用程序引擎的Python 2.7教程將無法運行

我的app.yaml教程是:

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

handlers: 
- url:/
    script: helloworld.application 

和helloworld.py是:

import webapp2 


class MainPage(webapp2.RequestHandler): 

    def get(self): 
     self.response.headers['Content-Type'] = 'text/plain' 
     self.response.write('Hi') 


application = webapp2.WSGIApplication([ 
    ('/', MainPage), 
], debug=True) 

日誌輸出爲:

*** Running dev_appserver with the following flags: 
    --skip_sdk_update_check=yes --port=10090 --admin_port=8001 
Python command: /usr/bin/python2.7 
Traceback (most recent call last): 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 182, in <module> 
    _run_file(__file__, globals()) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/dev_appserver.py", line 178, in _run_file 
    execfile(script_path, globals_) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 695, in <module> 
    main() 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 688, in main 
    dev_server.start(options) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 525, in start 
    options.yaml_files) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 556, in __init__ 
    server_configuration = ServerConfiguration(yaml_path) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 82, in __init__ 
    self._yaml_path) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 272, in _parse_configuration 
    return appinfo_includes.ParseAndReturnIncludePaths(f) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/appinfo_includes.py", line 63, in ParseAndReturnIncludePaths 
    appyaml = appinfo.LoadSingleAppInfo(appinfo_file) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/appinfo.py", line 1715, in LoadSingleAppInfo 
    listener.Parse(app_info) 
    File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse 
    self._HandleEvents(self._GenerateEventParameters(stream, loader_class)) 
    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 

我正在使用python 2.7運行在macbook pro上2.7 我正在使用應用程序引擎啓動程序。有任何想法嗎?

+0

你的例外被切斷了嗎?我認爲最後一行的'EventError'異常名稱後應該有一個錯誤消息。 –

+0

不,它沒有被切斷,多數民衆贊成在 – user2558615

+0

保存與文本wrangler app.yaml後,我設法得到更多的信息錯誤。 'google.appengine.api.yaml_errors.EventError:未知的網址處理程序類型。 in「/ Users/Evan/helloworld/app。yaml「,第9行,第1列 ' – user2558615

回答

10

我也遇到過同樣的問題。當您直接從網站複製時,它與文件編碼有關。避免這樣做,並確保您的文件具有適當的yaml編碼。這裏有一個例子讓你開始爲app.yaml文件

application: your-app-id 
version: 1 
runtime: python27 
api_version: 1 
threadsafe: true 

handlers: 
- url: /.* 
    script: helloworld.application 
+0

是的,這是問題所在,最終我找到了答案,但這是一個不幸的時間浪費,謝謝 – user2558615

+0

非常有幫助謝謝!!! – jap1968

4

我剪切和粘貼的app.yaml從鉻進GNOME終端,並得到了同樣的錯誤。最終我在vi中打開了app.yaml,發現它包含一個UTF文本方向標記。只要我刪除了,一切都開始工作。

故事的道德:如果你看到這個錯誤,檢查你的app.yaml壞標記,壞字符和其他任何不好的東西。 (但不是DOS換行符 - 開發應用程序服務器應付這些。)

1

嘗試刪除app.yaml中的應用程序行之前的特殊字符。它似乎不在那裏,但只需將光標移動到之前按下退格鍵之前的位置即可將其刪除。

8

在我的情況下,問題是「腳本」行的縮進級別。

它是這樣的:

handlers: 
- url: /.* 
script: helloworld.php 

,但應該是這樣的:

handlers: 
- url: /.* 
    script: helloworld.php 
+0

arrgh蟒蛇... –

0

要完成@Fernando巴索的回答,對劇本線正確的意圖應該是兩個空間,但不一個標籤,因爲它會被讀作一個\ t字符,這也會產生一個錯誤。