How do I create a GET request with parameters?

The HTTP request will be a POST instead of a GET when the data parameter is provided. Try urllib2.urlopen('http://httpbin.org/get?hello=there') instead.


If you are making a GET request then you want to pass query string. You do that by placing a question-mark '?' at the end of your url before the params.

import urllib
import urllib2

params = urllib.urlencode(dict({'hello': 'there'}))
req = urllib2.urlopen('http://httpbin.org/get/?' + params)
req.read()

you could use, much the same way that post request:

import urllib
import urllib2

params = urllib.urlencode({'hello':'there', 'foo': 'bar'})
urllib2.urlopen('http://somesite.com/get?' + params)

The second argument should only be supplied when making POST requests, such as when sending a application/x-www-form-urlencoded content type, for example.