2013-07-07 47 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字符,这也会产生一个错误。