This is my app.yml file
application: hello
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /.*
script: hello.py
The hello.py is located at the same directory as the app.yml file.
When I run the app I get this error:
google.appengine.api.yaml_errors.EventError: Unknown url handler type.
<URLMap
secure=default
static_files=None
application_readable=None
auth_fail_action=redirect
require_matching_file=None
static_dir=None
redirect_http_response_code=None
http_headers=None
url=/.*
script=None
upload=None
api_endpoint=None
expiration=None
position=None
login=optional
mime_type=None
>
in "C:\Users\***\Desktop\app\app.yaml", line 8, column 1
2016-03-01 11:36:12 (Process exited with code 1)
I thought it was spacing that was the issue so I added two spaces after script but I am still getting the same error.
You need to change the definition of your handler in app.yaml to:
application: hello
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /.*
script: hello.app
Pay close attention to the script: property. It should be pointing to your WSGIApplication, which for the example above is defined within the app variable.
Related
I am Trying to make a simple website with a image in it by using google app Engine. I am unable to make it.
My App.yaml code is below:
application: simplegraph-007
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /image/.*
static_dir: static/image/.*
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
My Main.py looks like:
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write("<img src ='/image/Ris.jpeg'/>")
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
My log is here:
INFO 2015-10-19 18:46:39,111 module.py:786] default: "GET /image/Ris.jpeg HTTP/1.1" 404 154
I hope to have help from you.
Thanks,
You can serve static images like this.
In app.yaml
- url: /image
static_dir: image
In your app root folder, create a folder /image and put Ris.jpeg there.
Folder layout should look similar to this
+ image
|
-- Ris.jpeg
- app.yaml
- main.py
GET /image/Ris.jpeg will now return the image file.
Also see the docs.
Check your logs when you start your app locally. I am sure it is printing an error. This is invalid for static_dir
- url: /image/.*
static_dir: static/image/.*
It does not need a wildcard. It should read:
- url: /image
static_dir: static/image
Your image in your local filesystem should be static/image/Ris.jpeg.
Using google app engine launcher, I can't seem to deploy my app due to this:
email=martinchua99#gmail.com', '--passin', 'update', 'C:\Users\admin\Desktop\school work\customtinywebdb']"
Usage: appcfg.py [options] update | [file, ...]
appcfg.py: error: Error parsing C:\Users\admin\Desktop\school work\customtinywebdb\app.yaml: mapping values are not allowed here
in "C:\Users\admin\Desktop\school work\customtinywebdb\app.yaml", line 1, column 24.
2014-11-25 19:46:48 (Process exited with code 2)
This is my yaml file,whats wrong with it?
application: camel-cars: 1
runtime: python
api_version: 1
handlers:
- url: /images
static_dir: images
url: .*
script: main.py
Yaml files are sensitive to white spaces. Also you are missing key words and new lines. Give this a try:
application: camel-cars
version: 1
runtime: python27
api_version: 1
threadsafe: false
handlers:
- url: /images
static_dir: images
- url: .*
script: main.py
For a blog project, I'm trying to set different webapp2 handlers for different urls. One of them is the "permalink" url of a post (accessed by post id). Another one is the url for deleting said post. When I try to go to such url, I get a blank page, and the AppEngineLauncher console says:
INFO 2014-01-20 08:08:42,574 module.py:612] default: "GET /del/5066549580791808 HTTP/1.1" 404 -
This is the code for the handlers part of my program:
application = webapp2.WSGIApplication([ ('/newpost', NewPost), #works OK
('/([0-9]+)', PermaLink), #works OK
('/del/([0-9]+)', Delete), #won't work!!!
('/', Front)], debug=True) #works OK
If somebody has some clue about this I'd appreciate it. I've been looking for a solution but the fact that I get no error message and it doesn't seem (to me at least) to make any sense makes it so much harder.
EDIT:
The app.yaml file:
application: blogapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
static_dir: static
- url: /.*
script: base.application
libraries:
- name: jinja2
version: latest
The Delete class is trivial code for testing, such as:
class Delete(Base): #Base is my base RequestHandler
def get(self, s):
self.response.write(s)
I even tried matching the urls '/del/([0-9]+)' to the same PermaLink class, and still doesn't work.
Nevermind, it's solved. I tidied up the yaml file and everything works correctly now.
application: blogapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: (/.*)*
script: base.application
libraries:
- name: jinja2
version: latest
I'm using Google App Engine with Python environment.
I have my main code in the main.py file. I want to create a new .py file for a different page.
I created the .py file, added the path to the yaml file. But I still get a '404 Error, resource not found'.
Here is my yaml file
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
- url: /hello
script: hello.app
libraries:
- name: webapp2
version: "2.5.2"
When the user goes to exampleurl.com/hello I want the hello.py file to be executed.
Here's the current content of hello.py
import webapp2
class HeyPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/html'
self.response.out.write('Hello, All!')
app = webapp2.WSGIApplication([('/hello', HeyPage)],
debug=True)
Here is the log:
INFO 2014-01-10 06:15:31,150 module.py:617] default: "GET /hello HTTP/1.1" 404 154
You should list your handlers from most specific to least specific. Your handler:
- url: .*
script: main.app
basically says that main.app should handle every url. Since it is the first in the list, main.py will try to handle every request regardless of the handlers that follow it in app.yaml. Change it to:
handlers:
- url: /hello
script: hello.app
- url: .*
script: main.app
And all should work.
As far as I can remember, GAE matches a URL with the patterns in handlers from top to down. .* matches with any URL and as it is the first pattern in the handlers section, it call main.app instead of your hello.app. You should place .* pattern at the end of the handlers section so that any URL that doesn't match with any of your previously defined URL patterns get handled by main.app.
So, modify your handlers section as:
application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /hello
script: hello.app
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
I'm having problems with Webapp2. When I put handlers for URLs that point to different python files in the app.yaml I get the following error:
ERROR 2012-10-06 16:44:57,759 wsgi.py:203]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 195, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 250, in _LoadHandler
__import__(cumulative_path)
ImportError: No module named application
My app.yaml:
application: [[app's name]]
version: 1
runtime: python27
api_version: 1
threadsafe: yes
inbound_services:
- mail
handlers:
- url: /send
script: email.application
- url: /_ah/mail/update#sitdown-standup.appspotmail.com.*
script: email.application
- url: /.*
script: SDSUmodels.application
libraries:
- name: webapp2
version: "2.5.1"
SDSUmodels.py ends with:
application = webapp2.WSGIApplication([('/info', MakeBasicInfo)],
debug=True)`
and email.py ends with:
application = webapp2.WSGIApplication([('/request', Request_update),
('/send', Send_report),
(Receive_email.mapping())],
debug=True)`
When I remove these lines
- url: /send
script: email.application
from app.yaml, the error stops, but this leaves me without a way to point a URL towards a particular file.
I can see some alternative ways of handling this in this question but I was wondering why this approach isn't working. I've done this previously with the old webapp version in a different project and it's worked – details below.
app.yaml:
application: [[other app's name]]
version: 1
runtime: python
api_version: 1
handlers:
- url: /stylesheets
static_dir: stylesheets
- url: /twitter
script: twitter.py
- url: /_ah/mail/kindle#shelvdtracker.appspotmail.com.*
script: kindle.py
- url: /.*
script: web.py
inbound_services:
- mail
twitter.py ends with:
application = webapp.WSGIApplication(
[('/twitter', Process_new_DM)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
There is a standard library named email as well; it is being loaded before your local module is being found.
Rename the module to something else and it'll work.