Python and urllib2: how to make a GET request with parameters

Posted by Infinity on Stack Overflow See other posts from Stack Overflow or by Infinity
Published on 2010-05-11T22:33:10Z Indexed on 2010/05/11 22:34 UTC
Read the original article Hit count: 274

Filed under:
|

I'm building an "API API", it basically a wrapper for a in house REST web service that the web app will be making a lot of requests to. Some of the web service calls need to be GET rather than post, but passing parameters.

Is there a "best practice" way to encode a dictionary into a query string? e.g.: ?foo=bar&bla=blah

I'm looking at the urllib2 docs, and it looks like it decides by itself wether to use POST or GET based on if you pass params or not, but maybe someone knows how to make it transform the params dictionary into a GET request.

Maybe there's a package for something like this out there? It would be great if it supported keep-alive, as the web server will be constantly requesting things from the REST service.

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about urllib2