forwarding a post in python

1 minute read

Wanted to run some data validation on a post request, then forward that request onto a different url.
Used urllib2, although it wasn’t exactly intuitive.
In my python code, I receive an django.http Request object.
To forward the request on, I did:
|newReq=urllib2.Request(‘urlToFrwardTo’,urllib.urlencode(req.POST))
and then
|urllib2.urlopen(newReq)

The part that weirded me out was the why I needed to urlencode the post. The post parameters don’t go in the url! Why would I urlencode them?
Whatever, it didn’t work unless I called ‘urllib.urlencode’ on the reqiest’s POST parameters. Weird.

Leave a Reply