I'm getting a 404 in google cloud endpoints on app engine - python

In my app, the app.yaml (the relevant part) looks like this:
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /logs
script: logviewer.main.app
- url: /static
static_dir: static
- url: /(.*\.html)
static_files: pages/\1
upload: pages/(.*\.html)
- url: /_ah/spi/.*
script: api.application
- url: .*
script: main.app
I've included all handlers, just to make sure, but I'm quite certain that app.yml isn't the problem.
The relevant part of api.py
#endpoints.api(name='quizservice',version='v01',
description='api backand for quickbuzzer')
class QuizService(remote.Service):
#endpoints.method(messages.VoidMessage , messages.CreateQuizResponse, name="createQuiz")
def createQuiz(self, request):
. . .
application = endpoints.api_server([QuizService],
restricted=False)
Now, when I visit the explorer and try running the QuiizService.createQuiz method, I get a 404 back.
Looking at the logs, I see this:
INFO 2013-04-29 17:53:15,560 server.py:561] default: "GET /_ah/api/discovery/v1/apis/quizservice/v01/rest HTTP/1.1" 200 2738
INFO 2013-04-29 17:53:22,118 server.py:561] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 1585
WARNING 2013-04-29 17:53:22,119 api_config_manager.py:201] No endpoint found for path: quizservice/v01
INFO 2013-04-29 17:53:22,119 server.py:561] default: "POST /_ah/api/quizservice/v01 HTTP/1.1" 404 9

I was able to solve the issue by supplying a path parameter to the endpoints.method decorator. What I'm wondering now, is if the endpoints api could choose a default path based on my method name.

Another case where this error can be thrown is with incorrect order of url handlers declaration.
See https://stackoverflow.com/a/15675839/362953
- url: .*
script: main.app
Should come at the end, not before
- url: /_ah/spi/.*
script: api.application
In this case of OP the order is correct.

Related

Google App Engine, Web2Py, and Cron, unable to assign value to attribute for url error

I'm having some trouble creating a Google App Engine Cron task for my Web2Py application. I've looked at the instructions for GAE Cron, and this is the task I created as a test:
my cron.yaml file is in the same directory as my app.yaml,
the path to my python controller is applications/data/default, and
the url to access the function is myapp.appspot.com/data/default/test.
This is my cron task entry:
cron:
- description: test
url: data/default/test
schedule: every 2 minutes synchronized
however, I'm getting this error when I try to deploy:
Unable to assign value 'data/default/test' to attribute 'url':
Value 'data/default/test' for url does not match expression '^(?:^/.*$)$'
This is the handlers portion of my app.yaml file:
handlers:
# Warning! Static mapping - below - isn't compatible with
# the parametric router's language logic.
# You cannot use them together.
- url: /(.+?)/static/_(\d+\.\d+\.\d+)\/(.+)
static_files: applications/\1/static/\3
upload: applications/(.+?)/static/(.+)
secure: optional
expiration: "365d"
- url: /(.+?)/static/(.+)
static_files: applications/\1/static/\2
upload: applications/(.+?)/static/(.+)
secure: optional
- url: /favicon.ico
static_files: applications/welcome/static/favicon.ico
upload: applications/welcome/static/favicon.ico
- url: /robots.txt
static_files: applications/welcome/static/robots.txt
upload: applications/welcome/static/robots.txt
- url: .*
script: gaehandler.wsgiapp # WSGI (Python 2.7 only)
secure: optional
I'm pretty lost here, as I'm not too familiar with google app engine or web2py. Any help would be appreciated
You're missing a slash in your cron.yaml url specification:
cron:
- description: test
url: /data/default/test
schedule: every 2 minutes synchronized

My google app engine website is only displaying my main page after migrating to python 2.7

Can anyone give me some pointers on how to get the other pages to show?
I this is my main.py
import webapp2
import os
import jinja2
jinja_environment = jinja2.Environment(autoescape=True,
loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__))))
class MainPage(webapp2.RequestHandler):
def get(self):
template = jinja_environment.get_template('index.html')
self.response.write(template.render())
application = webapp2.WSGIApplication([
('/',MainPage),
], debug=True)
And this is my app.yaml
application: ftmyersptcong
version: 1
runtime: python27
api_version: 1
threadsafe: true
libraries:
- name: jinja2
version: latest
handlers:
- url: /styles
static_dir: styles
- url: /images
static_dir: images
- url: /scripts
static_dir: scripts
- url: /.*
script: main.application
I keep getting a 404 Not Found Page when I to click on any of the links to other pages which have been href'd in my html code.
This is what is in the log:
INFO 2014-11-12 18:15:42,434 module.py:652] default: "GET / HTTP/1.1" 500 -
INFO 2014-11-12 18:28:21,151 module.py:652] default: "GET / HTTP/1.1" 200 1274
INFO 2014-11-12 18:28:21,272 module.py:652] default: "GET /styles/main.css HTTP/1.1" 200 1880
INFO 2014-11-12 18:28:27,512 module.py:652] default: "GET /downloads.html HTTP/1.1" 404 154
You have a handful of static directory routes defined in your app.yaml (images, scripts, styles) -- that's why your css file is loading fine, for example. Then you have everything not matching those directories going to "application" in your "main.py" file.
In there, you are currently only defining one route -- "/" and MainPage is defined as your handler for that route. Calls to "/downloads.html" get sent to that same router, but since it doesn't match the "/" route, a 404 is returned.
You need to define your other route(s) and handlers in your main.py. For example:
application = webapp2.WSGIApplication([
('/',MainPage),
('/downloads.html',DownloadPage)
], debug=True)
Then you'd define DownloadPage similarly to MainPage to handle that route. You can also do pattern matches in the route definition in order to pass along variable info, but for your example, the above should work.

Google App Engine only deploying *some* images

I recently deployed a website for my dad using Google App Engine.
Oddly, some images in the gallery are found, while some return with a 404. I looked in the admin dashboard for usage rates, and it says I'm only at 17% of "Code and Static File Storage".
I have tried changing the directory and re-deploying, I have also created a second application (from this-site-1 to this-site-2), and I have waited about an hour in case it's simply the cache, but none of these seem to be the issue.
I'm brand new to Google App Engine, this is the first website I've deployed using it, so any help would be much appreciated.
app.yaml
application: this-site-2
version: 1
runtime: python
threadsafe: true
api_version: 1
handlers:
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /css
static_dir: static/css
- url: /img
static_dir: static/img
- url: /js
static_dir: static/js
- url: /.*
script: main.py
Edit: I updated python to 2.7 in case that was the problem, but I did by doing this:
application: this-site-2
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /css
static_dir: static/css
- url: /img
static_dir: static/img
- url: /js
static_dir: static/js
- url: /.*
script: main.app # a WSGI application in the main module's global scope
libraries:
- name: webapp2
version: "2.5.1"
- name: django
version: "1.2"
skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?.*\.bak$
- ^(.*/)?.*\.less$
Then I deployed, and the console said that the deployment was successful and it was updating the indexes and exited with code 0. Then I tried to go to the website and it returned with a 500 server error. So I downgraded back to python 2.5 and the site is fine.
I think your image url handler is more complicated than it needs to be. I would suggest:
Put all static content (images, Javascript, CSS) in a folder called static or similar with subfolders for images, Javascript and CSS.
Use the following handler instead of your current image handler:
handlers:
- url: /images
static_dir: static/images
All files in the static/images folder will then be accessible on the url yourwebsite.com/images/subpath/image.jpg.
For more inspiration, see this app.yaml.
I had this problem and it turned out that it deploying images with lower case file extensions like this: name.png, but not ones with capital file extensions like this: name.PNG. Helpfully Windows hides this from you, so you can't always tell.
Ah, my dad solved it;
Simply change the jpg images that aren't working to a png image (and vice versa, if it's a png image not working, convert it to a jpg)

How to upload sitemap.xml through app engine?

I am using google app engine to host my website. I tried to upload sitemap.xml, but when I open the link i.e., www.example.com/sitemap.xml it shows Oops! This link appears to be broken.. I don't know the reason for this. Can anyone tell me what I am doing wrong?
Here is the content of my app.yaml file
application: mywebsite
version: 1
runtime: python
api_version: 1
handlers:
- url: /(.*\.(gif|png|jpg|ico|js|css))
static_files: \1
upload: (.*\.(gif|png|jpg|ico|js|css))
- url: .*
script: main.py
- url: /icon\.ico
static_files: icon.ico
upload: icon.ico
- url: /sitemap.xml
static_files: static/sitemap.xml
upload: static/sitemap.xml
- url: /static
static_dir: static
From here, "Patterns are evaluated in the order they appear in the app.yaml, from top to bottom. The first mapping whose pattern matches the URL is the one used to handle the request.".
You should try moving the catch all handler (url: .*) to the end of the file.

Every request hits server twice in Appengine

I have small app in appengine. Every request hits the server twice in my local dev server.
In debug mode i can see that the get method called twice.
Its happening in both chrome and firefox browsers.
here is the log from my localserver..
INFO 2011-03-12 00:44:31,076 dev_appserver.py:3317] "GET /movie/tanu_weds_manu/rating-review-video HTTP/1.1" 200 -
INFO 2011-03-12 00:44:32,345 dev_appserver.py:3317] "GET /css/fb.css HTTP/1.1" 200 -
INFO 2011-03-12 00:44:32,588 dev_appserver.py:3317] "GET /css/wianga-movie.0.1.css HTTP/1.1" 200 -
INFO 2011-03-12 00:45:46,648 dev_appserver.py:3317] "GET /movie/tanu_weds_manu/rating-review-video HTTP/1.1" 200 -
INFO 2011-03-12 00:45:46,911 dev_appserver.py:3317] "GET /img/wianga-fb-50.gif HTTP/1.1" 200 -
INFO 2011-03-12 00:45:47,177 dev_appserver.py:3317] "GET /img/arrow_green.gif HTTP/1.1" 200 -
INFO 2011-03-12 00:45:47,470 dev_appserver.py:3317] "GET /image/movie/tanu_weds_manu HTTP/1.1" 200 -
INFO 2011-03-12 00:45:47,717 dev_appserver.py:3317] "GET /js/jquery.qtip-1.0.0-rc3.min.js HTTP/1.1" 200 -
INFO 2011-03-12 00:45:47,970 dev_appserver.py:3317] "GET /js/wianga.0.1.js HTTP/1.1" 200 -
INFO 2011-03-12 00:46:37,473 dev_appserver.py:3317] "GET /movie/tanu_weds_manu/rating-review-video HTTP/1.1" 200 -
Updated: Its getting worse,i cheked the logs in app console.There it hits more than 3 times for a request.
handlers:
- url: /favicon.ico
static_files: static/img/favicon.ico
upload: static/img/favicon.ico
- url: /robots.txt
static_files: static/robots.txt
upload: static/robots.txt
- url: /img
static_dir: static/img
- url: /images
static_dir: static/images
- url: /css
static_dir: static/css
- url: /js
static_dir: static/js
- url: /image/.*
script: /wianga/pages/common/ImageController.py
- url: /task/.*
script: /wianga/pages/task/TaskController.py
- url: /browse/.*
script: /wianga/site/Browse.py
- url: /movie/(.*)/rating-review-video/
script: /wianga/site/MoviePage.py
- url: /movie/(.*)/rating-review-video
script: /wianga/site/MoviePage.py
- url: /404
script: /wianga/404/404.py
- url: /api/.*
script: /wianga/api/ApiController.py
- url: /.*
script: /wianga/site/Home.py
Am getting same behavior in hellowrld application from appengine turorial...
App.yaml
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: helloworld.py
Log for hello world example for single request...
INFO 2011-03-12 06:08:06,299 dev_appserver_main.py:507] Running application wianga-movie on port 8080: http://localhost:8080
INFO 2011-03-12 06:08:12,506 dev_appserver.py:3317] "GET / HTTP/1.1" 200 -
INFO 2011-03-12 06:08:13,721 dev_appserver.py:3317] "GET / HTTP/1.1" 200 -
INFO 2011-03-12 06:08:13,838 dev_appserver.py:3317] "GET /favicon.ico HTTP/1.1" 200 -
INFO 2011-03-12 06:08:13,953 dev_appserver.py:3317] "GET / HTTP/1.1" 200 -
When I set up my app.yaml I just poured through this page: http://code.google.com/appengine/docs/python/config/appconfig.html
You have to think like a regular expression parser. Anything that fails to match the preceding expressions will fall through to your wildcard handler and cause weirdness.
One thing I notice is that you should add login: admin to your task queue handler. This will prevent external requests from hitting that URL accidentally.
Also, when you are submitting tasks to your handler, if you don't include the trailing slash (/task?blah=something instead of /task/?blah=something) the request would fall through to your wildcard handler and get sent to Home.py. That could also happen for /image/, /browse/ and /api/. You should put logging calls into those handlers to make sure they are getting called when expected.
Nothing jumps out at me as obviously wrong in your app.yaml though. But since there are GETs showing up in your log, that indicates that something is requesting that URL, and it's not just the get method getting called twice internally.
Edit:
Hold on a sec, just noticed that you have this in your app.yaml twice. You shouldn't need to do that.
- url: /movie/(.*)/rating-review-video/
script: /wianga/site/MoviePage.py
- url: /movie/(.*)/rating-review-video
script: /wianga/site/MoviePage.py`
Try replacing with:
- url: /movie/(.*)/rating-review-video.*
script: /wianga/site/MoviePage.py`
Edit2:
Try adding this to the top of your get method:
logging.info('environ: ' + str(self.request._environ))
Pop the output into a beautifier ( http://jsbeautifier.org/ ) to make it more readable, and take a look at the REQUEST_METHOD, QUERY_STRING, HTTP_USER_AGENT, HTTP_COOKIE, PATH_INFO, and HTTP_REFERER params to see where the requests are actually coming from. If they are all coming from your browser then there is something weird in your html, like hidden iframes (are you using Channel API?).
Also, try going to http://localhost:8080/_ah/admin/queues and making sure there aren't any old tasks hanging around.

Categories