views:

307

answers:

2
application = webapp.WSGIApplication(
    [(r'/main/profile/([a-f0-9]{40})', ProfileHandler)],
    debug=True)

The regex in the above parameter will not recognize a 40 hex long hexdigest in Google App Engine.

I'm getting 404s instead of ProfileHandler being passed the matching 40 hex long profile ID. My app.yaml passes everything /main/.* to the correct python script so that's not the issue. The regex looks sane and resembles the example regex in GAE docs. What is wrong with this regex?

A: 

I have no experience with the Google App Engine, but:

  • what happens if you change ([a-f0-9]{40}) in to ([a-fA-F0-9]{40})
  • are you sure group $1 is used and not the entire match (including /main/profile/)?
Bart Kiers
no such luck adding uppercase to the mix. i cannot be sure about answering your second inquiry, because any 40 hex i slap on the end of /main/profile/ brings me to a completely uninformative 404 page. the $1 group is supposed to pass to ProfileHandler as a parameter. if it got that far, i could tell if it is matching $1 or the entire uri
Too bad. You'll have to wait or someone who's familiar with the Google App Engine then. Good luck!
Bart Kiers
+1  A: 

I can not reproduce your problem. Here is an exact code I have:

index.py

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class ProfileHandler(webapp.RequestHandler): 
    def get(self, *ar, **kw):
        self.response.out.write("PROFILE IS:" + ar[0])

run_wsgi_app(webapp.WSGIApplication(
[(r'/main/profile/([a-f0-9]{40})', ProfileHandler),],
                                 debug=True))

app.yaml

application: someapp
version: 1
runtime: python
api_version: 1

handlers:
- url: /main/.*
  script: index.py

Application is listening on port 8082

GET: http://localhost:8082/main/profile/4c4f630aef49c0065c22eb3dd35a00f5787f4816
RESPONSE: PROFILE IS:4c4f630aef49c0065c22eb3dd35a00f5787f4816
Nulldevice
I tried using *ar instead of just ar as a parameter, which didn't work at first. Then I changed it back to plain ar, tried uploading it to GAE and got an error that get() takes exactly 2 parameters. After changing ar back to ar*, the regex matched up and the page loaded. End result: hexdigest matching works properly now. Thanks for your and Bart K's help!