1

I'm using Python 2.7 in Google App Engine and can't seem to get my app.yaml file set up right.

My goal is so that if I go to http://localhost/carlos/ I get an executed carlos.py

Here is my directory structure:

app\
   \app.yaml
   \main.py
   \carlos.py

Here is my current app.yaml file:

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

handlers:
- url: /carlos/.*
  script: carlos.app

- url: .*
  script: main.app

and my carlos.py file is:

import webapp2

class MainHandler(webapp2.RequestHandler):
  def get(self):
    self.response.out.write("Hello, Carlos!")

app = webapp2.WSGIApplication([('/carlos', MainHandler)],
                              debug=True)

However all I'm getting now is a 404 Not Found error. Any thoughts?

2 Answers 2

4

I was able to determine the solution and figured I'd post it for anyone out there.

In my carlos.py file I needed to replace:

app = webapp2.WSGIApplication([('/', MainHandler)],
                              debug=True)

with

app = webapp2.WSGIApplication([('/carlos/', MainHandler)],
                              debug=True)

It appears that the first argument for the WSGIApplication is referring to the TOTAL path from your root web address as opposed to the INCREMENTAL path from which it was originally directed.

I'm selecting this answer over what was provided by Littm because I'd like to keep using WSGI

Sign up to request clarification or add additional context in comments.

Comments

1

It worked with the following modifications:

1 - Replacing "carlos.app" by "carlos.py" and "main.app" by "main.py" in the yaml file.

2 - Add a slash ("/") after " /carlos " in the file "carlos.py".

3 - Add the following part of code in the end of each python files (carlos.py and main.py)

def main():
    app.run()

Here is an example of modified files:

app.yaml :

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

handlers:
- url: /carlos/.*
  script: carlos.py

- url: .*
  script: main.py

carlos.py : import webapp2

class MainHandler(webapp2.RequestHandler):
  def get(self):
    self.response.out.write("Hello, Carlos!")

app = webapp2.WSGIApplication([('/carlos/', MainHandler)],
                          debug=True)

def main():
    app.run()

main.py :

import webapp2

class MainHandler(webapp2.RequestHandler):
  def get(self):
    self.response.out.write("Hello, MAIN!")

app = webapp2.WSGIApplication([('/', MainHandler)],
                          debug=True)

def main():
    app.run()

You can try navigating to:

localhost:8080/carlos/ and localhost:8080/ to see the results

Hope it helps ;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.