user2558615
user2558615

Reputation: 103

Google app engine python 2.7 tutorial won't run

I'm following the tutorial at https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction

my app.yaml is:

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

handlers:
- url: /
  script: helloworld.application

and helloworld.py is:

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)

The log output is:

*** 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

I'm running on a macbook pro, using python 2.7 I'm using the app engine launcher. Any ideas?

Upvotes: 10

Views: 6072

Answers (5)

JDenais
JDenais

Reputation: 3016

To complete on @Fernando Basso's answer, the correct intent on the script line should be two spaces, but not a tab as it would be read as a \t character which would also generate an error.

Upvotes: 0

Fernando Basso
Fernando Basso

Reputation: 708

In my case the problem was the indentation level of the "script" line.

It was like:

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

but should be like this:

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

Upvotes: 8

Wedava
Wedava

Reputation: 1231

Try deleting the special character before the application line in app.yaml. It seems not to be there but just navigate your cursor to the position before a then press backspace to delete it.

Upvotes: 1

Dave Hughes
Dave Hughes

Reputation: 96

I cut-and-pasted app.yaml from Chrome into gnome-terminal, and got the same error. Eventually I opened app.yaml in vi, and found that it contained a UTF text-direction marker. As soon as I removed that, everything started working.

Moral of the story: if you see this error, check your app.yaml for bad markup, bad characters, and anything else bad. (Not DOS newlines though -- the dev appserver copes with those.)

Upvotes: 4

zipate
zipate

Reputation: 166

I experienced the same problem too. It has something to do with the file encoding when you copy directly from the site. Avoid doing this and ensure that your file has proper yaml encoding. Here's an example to get you started for the app.yaml file

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

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

Upvotes: 10

Related Questions