Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I receive percent encoded slashes with Django on App Engine?

I'm using Django with Google's App Engine.

I want to send information to the server with percent encoded slashes. A request like http:/localhost/turtle/waxy%2Fsmooth that would match against a URL like r'^/turtle/(?P<type>([A-Za-z]|%2F)+)$'. The request gets to the server intact, but sometime before it is compared against the regex the %2F is converted into a forward slash.

What can I do to stop the %2Fs from being converted into forward slashes? Thanks!

like image 328
J. Frankenstein Avatar asked Jun 14 '10 20:06

J. Frankenstein


Video Answer


1 Answers

os.environ['PATH_INFO'] is decoded, so you lose that information. Probably os.environ['REQUEST_URI'] is available, and if it is available it is not decoded. Django only reads PATH_INFO. You could probably do something like:

request_uri = environ['REQUEST_URI']
request_uri = re.sub(r'%2f', '****', request_uri, re.I)
environ['PATH_INFO'] = urllib.unquote(request_uri)

Then all cases of %2f are replaced with **** (or whatever you want to use).

like image 150
Ian Bicking Avatar answered Oct 19 '22 23:10

Ian Bicking