开发者

Problem with redirection in python appengine

I am trying to create some alias ::

util.run_wsgi_app(webapp.WSGIApplication([
    (r"/(.{1,2})", MainPage)
], debug=debug)

class MainPage(webapp.RequestHandler):
def get(self,token):
    token_dict = {
        'fb':'http://www.facebook.com/anilashanbhag',
        '+' :'http://plus.google.com/106274357148468411814',
        't' :'http://twitter.com/masteranil'
    }
    logging.debug(token)
    if token in token_dict:
        self.redirect(token_dict[token])
    else:
        self.redirect('/')

The problem is that fb and t work but + doesnt. I wa开发者_运维知识库s thinking appengine is encoding the url but then logs show /+ 404 ....


The + is a reserved character outlined in RFC 1738 - Uniform Resource Locators (URL) specification. It's reserved because it is used as part of the delimiter syntax in URL's. Try URL Encoding your character (%2B) and see if that helps.


Ok for the sake of completion : The correct answer is :: "%2B" is 3 characters; this is what application is receiving, the 404 is because the handler doesn't match more than 2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜