Search code examples
pythonhttp-redirectunicodewebapp2

Redirect to a page with a Japanese character parameter using webapp2


In my webapp I want to redirect from a POST to a GET to another URL and set a parameter for the GET as a Japanese character.

This works:

self.redirect("SomePage?param=%s" % "value")

This raises an encoding error inside redirect:

self.redirect("SomePage?param=%s" % u"が")

Is there any way to redirect and set that Japanese character parameter for the redirect-to page?


Solution

  • The query string should be both encoded as 'utf-8', and percent-encoded:

    >>> import urllib
    >>> 'SomePage?%s' % urllib.urlencode({'param': u'が'.encode('utf-8')})
    'SomePage?param=%E3%81%8C'