M3105 M3105 - 1 year ago 248
JSON Question

Making a GET request JSON with parameters using Python

I was wondering how do I make a GET request to a specific url with two query parameters? These query parameters contain two id numbers
So far I have:

import json, requests
url = 'http://'

But they gave me query paramters first_id=### and last_id=###. I don't know how to include these parameters?

Answer Source

To make a GET request you need the get() method, for parameters use params argument:

response = requests.get(url, params={'first_id': 1, 'last_id': 2})

If the response is of a JSON content type, you can use the json() shortcut method to get it loaded into a Python object for you:

data = response.json()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download