Regex match of hexdigest in google app engine webapp WSGIApplication
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 he开发者_开发知识库x 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?
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
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/
)?
精彩评论