I am trying to process inbound emails (on dev server) sent to different addresses like:
- url: /_ah/jogo#.*rpg2e\.appspotmail\.com
script: jogo.py
- url: /_ah/contato#.*rpg2e\.appspotmail\.com
script: contato.py
- url: /.*
script: helloworld.py
but I get the following log message:
INFO 2012-07-27 20:05:31,759 dev_appserver.py:2952] "POST /_ah/mail/jogo#rpg2e.appspotmail.com HTTP/1.1" 404 -
I also tried:
- url: /_ah/jogo#rpg2e\.appspotmail\.com
script: jogo.py
- url: /_ah/contato#rpg2e\.appspotmail\.com
script: contato.py
- url: /.*
script: helloworld.py
to no avail.
If I simply use a handle_all it works like a charm, but I would like my script only to handle email sent to the correct handle#rpg2e.appspotmail.com
After spending some time searching the Web and within Stack Overflow, I came across many questions like mine, and the only working solution was to use the catch all approach. Some of them were even answered by Ikai Lane[1] with the same conclusion - only catch all works.
Then again, did anyone have success using multiple handlers?
[1] https://groups.google.com/forum/?fromgroups#!topic/google-appengine-java/UGTkMV9foJ0
From the Google App Engine Python - Receiving Mail
url: /_ah/mail/owner#.*your_app_id\.appspotmail\.com
script: handle_owner.py
login: admin
- url: /_ah/mail/support#.*your_app_id\.appspotmail\.com
script: handle_support.py
login: admin
You are missing the /mail/ portion of the required path. You're POSTING to /_ah/jogo#rpg2e.appspotmail.com instead of /_ah/mail/jogo#rpg2e.appspotmail.com. Try this instead:
- url: /_ah/mail/jogo#rpg2e\.appspotmail\.com
script: jogo.py
- url: /_ah/mail/contato#rpg2e\.appspotmail\.com
script: contato.py
Lastly, we all get a little tunnel vision every now and then when confronted with a problem, but it's worth noting the value in error messages. The error message tells us where App Engine is looking when it makes the POST request, which you could match up with your handlers:
INFO 2012-07-27 20:05:31,759 dev_appserver.py:2952] "POST /_ah/mail/jogo#rpg2e.appspotmail.com HTTP/1.1" 404
Related
I have a Google App working and I would like to make it run 2 python files instead of one. Here's my original handlers part of my app.yaml
handlers:
- url: /.*
script: enwebXML.app
Then I wanted to make it run 2 different python files but it just does whatever the first one is doing so it just ignores the seconde file.
handlers:
- url: /.*
script: enwebXML.app
- url: /.*
script: frwebXML.app
I just think that since it's the same url it doesn't go through the second one, I tried to change the urls to 2 sub urls but no chance it doesn't work for some reason, here's the urls I tried with:
-url: /en/.*
-url: /fr/.*
Since it doesn't work I would like to know if there's something I can do like:
handlers:
- url: /.*
script: enwebXML.app
script: frwebXML.app
The app.yaml pattern url routing works on a 1st match basis: whichever pattern matches first wins and the respective script is invoked - as you observed.
So you need 2 different routing patterns to route requests to 2 different scripts. You were on the right track:
handlers:
- url: /en/.*
script: enwebXML.app
- url: /fr/.*
script: frwebXML.app
Of course, you'll need to update accordingly the app handler mapping patterns in each of the scripts. Something like this:
in enwebXML.app change /some_path to /en/some_path
in frwebXML.app change /some_path to /fr/some_path
I have the following config file for my google appengine app in python:
application: testapp-94974206
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /helloworld
script: helloworld.application
- url: /
script: helloworld.application
when calling the url with no prefix (/) I get my "helloworld" app called, while when calling with /helloworld I get a 404 not found error page. What is wrong with the declaration of "/helloworld" above?
My question is actually close to another one that has been already answered here.
It turns out that the /helloworld url is actually well routed by the appengine, but then the culprit is the WSGI router that parses the whole absolute URL and not just the one relative to /helloworld, as I thought it would.
As the title indicates my API isn't visible in the explorer and all my logs show is the following:
INFO 2013-03-08 13:39:08,182 dev_appserver.py:723] Internal redirection to http://127.0.0.1:8080/_ah/spi/BackendService.getApiConfigs
INFO 2013-03-08 13:39:08,198 dev_appserver.py:3104] "GET /_ah/api/discovery/v1/apis HTTP/1.1" 500 -
The relevant handler from my app.yaml file looks as follows:
13 # Endpoint handlers
14 - url: /_ah/spi/.*
15 script: main.app
And my code from main.py is as follows:
from google.appengine.ext import endpoints
from protorpc import messages
class Location(messages.Message):
reg_id = messages.StringField(1)
phone_number = messages.StringField(2)
latitude = messages.StringField(3)
longitude = messages.StringField(4)
#endpoints.api(name='locations', version='v1', description='Location API for where are you app')
class LocationApi(remote.Service):
#endpoints.method(Location, Location, name='location.insert', path='location', http_method='POST')
def insert(self, request):
return request
app = endpoints.api_server([LocationApi])
Anyone got a clue about what I'm doing wrong?
Please check the following:
As you should be able to see from the logs, you're getting an import error. In main.py add this
from protorpc import remote
From the documentation:
Note: If you want to test authenticated calls to your API using the Google API Explorer, you must also supply its client ID, which is available through the Endpoints library as endpoints.API_EXPLORER_CLIENT_ID.
Check your logs again to make sure the code actually runs. You're getting a 500 because of a Python exception being raise and there may be other issues with your code, though it doesn't seem like from what you've posted.
It works now that I list the endpoint handler before the other handlers.
This works:
handlers:
# Endpoint handler
- url: /_ah/spi/.*
script: endpoints.app
# Page handlers
- url: /.*
script: home.app
This doesn't work:
handlers:
# Page handlers
- url: /.*
script: home.app
# Endpoint handler
- url: /_ah/spi/.*
script: endpoints.app
The problem is that your python file can't find the import for:
from protorpc import remote
Therefore use the terminal, skip the GUI, navigate to the appengine sdk directory and put your project in there. For mac it is:
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/
I'm using Python 2.7 and Google App engine. I've written a page that redirects a user to a form after Oauth has completed. This works perfectly on localhost, but it fails when I deploy to the app engine. What am I doing wrong?
The error message I get is "404. That’s an error. The requested URL /form was not found on this server. That’s all we know."
The server logs don't show my /form request at all.
Relevant snippets follow:
1.app.yaml
handlers:
- url: .*
script: public.main.app
builtins:
- remote_api: on
- admin_redirect: on
2.main.py
app = webapp2.WSGIApplication([
('/form?$', content.Home),
('/oauthcallback?$', content.CallbackHandler),],
debug=True)
3.content.py fxn for /oauthcallback
....
http = credentials.authorize(http)
self.redirect('/form')
Hooray!
Thanks guys for all your help.
#Dave Smith, that syntax: '/form?$' is perfectly alright.
It turns out that '/form' is reserved by the GAE. I renamed my entry and now it works perfectly.
See: https://developers.google.com/appengine/docs/python/config/appconfig#Reserved_URLs
I wanted to download the data on my online app's datastore, I followed the guide on code.google, I added this to my app.yaml file
builtins:
- remote_api: on
But when I updated using appcfg.py update src and called this:
appcfg.py download_data --application=myapp --url=http://myapp.appspot.com/remote_api_path --filename=first-test-backup`
I got an Authentication error, pretty much the same case mentioned here, so I tried putting this:
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
before any catch-all handlers, but then got this error: threadsafe cannot be enabled with CGI handler when I tried to update, so according to this discussion, I replaced it by:
- url: /remote_api
script: google.appengine.ext.remote_api.handler.application
login: admin
Which gave me again the authentication error, I also tried adding ('/remote_api', google.appengine.ext.remote_api.handler) to app = webapp2.WSGIApplication, however still the authentication error persists.
I use a High Replication datastore, but according to code.google the only drawback is that I might not get the latest data.
How can I download my data?
Try this:
builtins:
- remote_api: on
And for url
appcfg.py download_data --application=~myapp --url=http://myapp.appspot.com/_ah/remote_api --filename=first-test-backup
Atttention _ah in url: http://myapp.appspot.com/_ah/remote_api