Google App Engine Handler not displaying content - python

Hi I'm trying to get my Google App Engine application running on local host but I'm getting issues when I try to run it.
This is the code I'm tryng to run:
# helloworld.py
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
#"Test" text is not displayed
self.response.write("Test")
app = webapp2.WSGIApplication([('/', MainHandler)],
debug=True)
#This line prints the content
print "This works fine"
When I run the dev server on localhost I get Code 200 as response but the handler doesn't seems to be executed properly.
Any idea?

Your code looks fine, just make sure your in your app.yaml you have the handlers correct. It should look something like this:
application: helloworld
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: helloworld.app
libraries:
- name: webapp2
version: "2.5.2"
If you haven't done it yet, you should also complete the Getting Started tutorial.

I solved this issue. Using webapp2 library I have to add the folowing code to the *.yaml file:
libraries:
- name: webapp2
version: "2.5.2"

Related

Google app engine launcher while browsing project "No such projects are selected"

I have created folder that is apps, and that having the subfolder that is ae-01-trivial.Added app.yaml to the ae-01-trivial,
Following code are added to the app.yaml:
application: ae-01-trivial
version: 1
runtime: python34
api_version: 1
handlers: -
url: /.*
script: index.py
And also added index.py to the ae-01-trivial, it is having following code:
print 'Content-Type: text/plain'
print ' '
print 'Hello there Chuck' .
So here I have facing the problem is "no such projects are selected".
If you're trying to create a request handler in App Engine, follow this example. Also Google App Engine uses Python 2.7 runtime for Python applications, so 3.4 may not work.

Google App Engine Launcher is not running my hello world for Python Mac

I have tried all the existing resources but to no avail.
here is my app.yaml code:
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.app
Here is my webapp2 code:
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
All in my hello_world directory. I proceed to add existing application and point to the hello_world directory where helloworld.py (webapp2) script and the app.yaml code are living. I hit run on Google App Engine and it just stays loading, it never completes. Therefore, my http://localhost:8080/ page never loads.
You're missing the application: line in your app.yaml.
You're probably also gonna need to list the 3rd party webapp2 in the libraries section, something like this:
libraries:
- name: webapp2
version: "2.5.2"

MissingURLMapping: No URLMap entries found in application configuration

I'm new in GAE development, I've just created a simple API but I'm unable to run my app, because I keep getting the error No URLMap entries found in application configuration.
Here's my app.yaml file
application: gw2
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /_ah/spi/.*
script: main.api_server
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
And here is my main.py file where I've declared the api_server variable
from google.appengine.ext import endpoints
import api
api_server = endpoints.api_server([api.GW2Service])
GW2Service inherits from remote.Service
Edit I'm using command line tools (Ubuntu 12.04)
Where's the mistake?
Thanks in advance. Eric ~H
You start server from the app or command line?
Try using "import endpoints" not from ... import endpoints
In app.yaml set endpoints version to latest.
Move GW2Service to main.py and test if server is ok. The problem might be generated by file name "api".

Blank Page with web.py and Google App Engine

I'm trying to get web.py app running on local Google App Engine.
My yaml:
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: code.app
My code.py:
import web
urls = (
"/.*", "hello",
)
app = web.application(urls, globals())
class hello:
def GET(self):
return 'Hello, world!'
app = app.gaerun()
When I start the server all I get is a blank page. So what's wrong?
Edit:
python --version
Python 2.7.6
Edit 2:
Error from console:
ImportError: No module named web
What you're trying to do is import an external module, which is not supported by GAE.
What you can do though, is copy web.py into your app directory, and then use it. See "How to include third party Python libraries in Google App Engine".
You can get the source code from here

Getting Started with Python in Google App Engine

I'm just getting started in python with google app engine using the webapp2 framework and jinja2 templating. I can't seem to get my first and very simple script up and running. All I want is for the script to serve the index.html file(located in the same directory).
Here is the app.yaml file:
libraries
- name: webapp2
version: latest
- name: jinja2
version: latest
application: practice
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: practice.application
Here is practice.py:
import os
import webapp2
from jinja2 import Enviroment, FileSystemLoader
loader = jinja2.FileSystemLoader(os.path.dirname(__FILE__)
env = jinja2.Enviroment(loader)
class MainPage(webapp2.RequestHandler):
def get(self):
template = env.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
Update:
I am running this locally from the Google app engine launcher.
When I attempt to open the file I receive a server error with the description
The website encountered an error while retrieving http://localhost:9080/. It may be
down for maintenance or configured incorrectly."
Here's why your code won't run:
Your app.yaml is malformed
Enviroment is spelt wrong
Your missing a closing bracket on line 5
You haven't imported the jinja2 library
The variable __FILE__ is undeclared
Here's what I think your code should look like:
app.yaml
application: practice
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
handlers:
- url: /.*
script: practice.application
practice.py
import jinja2
import os
import webapp2
loader = jinja2.FileSystemLoader(os.path.dirname(__file__))
env = jinja2.Environment(loader=loader)
class MainPage(webapp2.RequestHandler):
def get(self):
template = env.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
I suggest you do the following to make your life a LOT easier:
download eclipse (I assume you haven't given the syntax errors) -> http://eclipse.org/
complete the tutorial -> https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction
read the docs -> https://developers.google.com/appengine/docs/python/
Hope this helps get you on your way.
Happy coding :)
In webapp2 you should use app instead of application, so last line should look like this:
app = webapp2.WSGIApplication([('/', MainPage),], debug=True)

Categories

Resources