_ah/ URLs being passed into app via app.yaml - google-app-engine

I've installed a CakePHP application onto App Engine, and I'm redirecting URLs into it using a wildcard URL in my app.yaml:
url: /.*
script: app/webroot/index.php
The documentation states that /_ah/* URLs will be ignored (I don't know what these are for yet), but they are being caught by my CakePHP app and throwing errors into the error log. I also suspect this is the cause of 500 errors with an appengine error of 204 that keep happening randomly.
Does anyone have a solution for this? How do I ensure that the /_ah/ urls pass through to the app engine and not my specific application code?
Example error:
E 08:51:48.957 2015-03-17 404 841 B 304ms /_ah/start
0.1.0.3 - - [17/Mar/2015:01:51:48 -0700] "GET /_ah/start HTTP/1.1" 404 841 - - "****.appspot.com" ms=304 cpu_ms=416 cpm_usd=0.000094 loading_request=1 instance=0 app_engine_release=1.9.18
E 08:51:48.854 error: [MissingControllerException] Controller class AhController could not be found.
MissingControllerException is thrown by my app.

Request to /_ah/start is an initial request from Appengine itself, to initialize your app. I think you can ignore it, if you don't need to do anything special. Or return empty response.
See docs: https://cloud.google.com/appengine/docs/php/modules/#PHP_Instance_states

Related

GAE TaskQueue hitting Endpoints API

I have an endpoint api named "gameApi"
I have an api called:
#ApiMethod(name = "startNewRound", path = "evaluateRound", httpMethod = HttpMethod.POST)
I'm trying to run the following task queue:
queue.add(
ofy().getTransaction(),
TaskOptions.Builder.withUrl("/_ah/api/gameApi/v1/evaluateRound")
.param("gameId", gameId.toString())
.method(TaskOptions.Method.POST)
.countdownMillis(5000));
I'm getting a 404 in the logs:
0.1.0.2 - - [14/Nov/2014:14:58:28 -0800] "POST /_ah/api/gameApi/v1/evaluateRound HTTP/1.1" 404 234 "https://some-appspot-123.appspot.com/_ah/spi/com.appspot.some_appspot_123.spi.GameAPI.playCard" "AppEngine-Google; (+http://code.google.com/appengine)" "some-appspot-123.appspot.com" ms=8 cpu_ms=21 cpm_usd=0.000026 queue_name=default task_name=62689306220576549071 instance=00c61b117c54ec2fb802c51c19fe26523ec51854 app_engine_release=1.9.16
It looks like it's hitting the HTTP and not the HTTPS page. Is there a way I can force it to use HTTPS?
In endpoints, HTTP 404 corresponds to com.google.api.server.spi.response.NotFoundException.
Is it possible that the method has not been defined in the API class, or that it doesn't have a correct annotation?
Also, it doesn't seem like it's hitting http, the trace clearly shows https as the protocol. I think it's only possible to use http on localhost.

How to display separate page if quota is exceeded?

I do it in accordance with Custom Error Responses - app.yaml is updated with
error_handlers:
- error_code: over_quota
file: templates/over_quota.html
and according file is created. But still error (exception) is shown instead of that page. I've tried to place the file in the root folder (with according update at app.yaml) - it didn't help.
What am I doing wrong?
Upd. I've defined that in the following way in accordance with #Gwyn Howell comment.
handlers:
- url: /over_quota.html
static_files: templates/over_quota.html
upload: templates/over_quota.html
error_handlers:
- error_code: over_quota
file: over_quota.html
But (1) how to test it, (2) which url user will see in result? http://www.example.com/over_quota.html or will it be original url?
You're going over a specific quota, such as datastore operations, which throws an exception, without going over your instance hours quota. The over quota error message is only shown if App Engine can't send a request to an instance at all due to lack of quota; if the request is sent to your app, but you attempt to do something that exceeds available quota, it's up to you to handle the exception as you see fit.

Navigating to /_ah/admin on localhost yields unknown 404 error

I'm currently porting my GAE app to Python 2.7 and have come across some exciting things that I've slowly been able to figure out one at a time (Hello, aliased simplejson library!). However, I'm currently at a loss to explain this particular issue.
Whenever I navigate to the Admin Console (http://localhost:8080/_ah/admin), I get a 404 page. This is strange in itself (This was working just fine before), but it also isn't my custom 404 page. This makes me think this is based on the built-in handlers, but I'm not sure what could be the cause.
Other fun facts:
There's no attempts to handle /_ah/.* in my app.yaml or elsewhere
Nothing has changed in my app.yaml aside from the usual script-to-WSGI handler stuff
No usage of Federated Logins
Over time I've turned on almost all of the builtins
The app deploys correctly and without issue
I'm using the GAE Launcher on OSX (Minor, but it does have some odd quirks about it)
Update
It's probably easier just to show the console logs of what is coming out. This is after the app has fully started and I have attempted to navigate to the admin page twice (The IO Error is cute, and only happens the initial time):
[Master] [dev_appserver_multiprocess.py:650] INFO Running application mygaeapp on port 8081: http://localhost:8081
[Master] [dev_appserver_multiprocess.py:652] INFO Admin console is available at: http://localhost:8081/_ah/admin
[Master] [dev_appserver_multiprocess.py:901] DEBUG balancer to port 9000
[App Instance] [0] [py_zipimport.py:139] WARNING Can't open zipfile /Library/Python/2.7/site-packages/slimmer-0.1.30-py2.7.egg: IOError: [Errno 13] file not accessible: '/Library/Python/2.7/site-packages/slimmer-0.1.30-py2.7.egg'
[App Instance] [0] [py_zipimport.py:139] WARNING Can't open zipfile /Library/Python/2.7/site-packages/NoseGAE-0.2.0-py2.7.egg: IOError: [Errno 13] file not accessible: '/Library/Python/2.7/site-packages/NoseGAE-0.2.0-py2.7.egg'
[App Instance] [0] [recording.py:372] INFO Saved; key: __appstats__:012400, part: 67 bytes, full: 8780 bytes, overhead: 0.000 + 0.007; link: http://localhost:8081/_ah/stats/details?time=1331638312442
[App Instance] [0] [dev_appserver.py:2865] INFO "GET /_ah/admin HTTP/1.1" 404 -
[Master] [dev_appserver_multiprocess.py:901] DEBUG balancer to port 9000
[App Instance] [0] [recording.py:372] INFO Saved; key: __appstats__:020100, part: 67 bytes, full: 9196 bytes, overhead: 0.000 + 0.007; link: http://localhost:8081/_ah/stats/details?time=1331638320129
[App Instance] [0] [dev_appserver.py:2865] INFO "GET /_ah/admin HTTP/1.1" 404 -
[Master] [dev_appserver_multiprocess.py:901] DEBUG balancer to port 9000
In case you found this answer and you're using App Engine SDK 1.7.6 or higher, the default URL has changed from localhost:8080/_ah/admin to localhost:8000.
So I finally tracked this down to something that works perfectly fine in Python 2.5, but breaks on Python 2.7 with dev_appserver only.
To turn maintenance mode on and off, we reassign the routes in the WSGI instance to point to a new set of URLs by changing the app.router field directly. Disabling this code path by checking the app version allows /_ah/admin to work correctly.
I had the same problem due to the fact that I defined a URL filter in my web.xml file:
<filter>
<filter-name>filter</filter-name>
<filter-class>com.example.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The filter class, MyFilter, has a doFilter method as below:
#Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String path = req.getRequestURI().substring(req.getContextPath().length());
if (path.equals("/")) { // Welcome path
request.getRequestDispatcher("/res/index").forward(request, response);
} else if (path.startsWith("/static") || path.startsWith("/_ah")) {
// Static content or internal and admin stuff
chain.doFilter(request, response); // Goes to default servlet.
} else { // Jersey servlet controller
request.getRequestDispatcher("/res" + path).forward(request, response);
}
}
The part in the code above reading || path.startsWith("/_ah") solved my problem, because the filter must allow paths starting with /_ah to go through unchanged.
I needed the filter so that Jersey could work without all my REST paths being prepended with /res or whatever is specified in web.xml.

App Engine Backends and Taskqueue URL login Error

I'm getting this error from a request called from the task queue. It suggests I need to change the app.yaml handler but I think I have the correct handler
Here is the error log entry:
2011-11-17 13:30:35.849 /tasks/kacher 302 209ms 0kb
0.1.0.1 - - [17/Nov/2011:13:30:35 -0800] "GET /tasks/kacher HTTP/1.1" 302 0 - - "rawload.XXX.appspot.com" ms=209 cpu_ms=0 api_cpu_ms=0 cpm_usd=0.000032 queue_name=default task_name=cf2e2f1d39d108b3972a1da8c6532fea
W2011-11-17 13:30:35.842
Request failed because URL requires user login. For requests invoked within App Engine (offline requests like Task Queue, or webhooks like XMPP and Incoming Mail), the URL must require admin login (or no login).
This is the code to call the task:
taskqueue.add(url='/tasks/kacher',target='rawload',method='GET')
Here is my app.yaml, with the task urls as login:admin which seems correct (to me):
- url: /tasks.*
script: main.py
login: admin
- url: .*
script: main.py
login: required
secure: always
There's a known bug in the dev_appserver with tasks that require admin login sometimes failing like this. Try logging your browser session in as an admin before accessing the URL that enqueues the task, or try uploading your app to production to see if you experience the issue there.

Google App Engine Error 0kb AppEngine-Google

I have a project on Google App Engine. It has 2 separate data-stores one which holds articles and the other holds any article which is classified as a crime. (True or False)
But when I try and run my cron to move the crime articles into the "crime" data-store I receive this error:
Has anyone experienced this and how did they over come it!?
0kb AppEngine-Google;
0.1.0.1 - - [22/Apr/2011:09:47:02 -0700] "GET /place HTTP/1.1" 500 138 - "AppEngine-Google;
(+http://code.google.com/appengine)"
"geo-event-maps.appspot.com" ms=1642
cpu_ms=801 api_cpu_ms=404
cpm_usd=0.022761 queue_name=__cron
task_name=740b13ec69de6ac36b81ff431d584a1a loading_request=1
As a result my cron fails.
I just had a similar problem where my cron was crashing due to the fact that it was finding an non-ascii character and not able to process it? Try encode('utf-8'). My cron's work ok without needing the login URL, but it's a good tip for future :-)
Just my 2 cents worth for your question ;-)
It's probably not related to cron. Trying to load your URL directly (http://geo-event-maps.appspot.com/place) returns an HTTP 500 error. As an admin of the app, you should be able to run any cron job without error just by pasting the URL into a browser, so start there.
By the way, make sure to require admin access to any cron URLs. As an unauthorized user I should have received a 401 error, not a 500. Even if you use just one handler, you can do something like this in your app.yaml:
- url: /cron/.*
script: main.py
login: admin
- url: /.*
script: main.py

Resources