Q. Is it possible to send json data with GET request?
I want to pass some filter parameters to read results from DB
params = {'is_coming_soon': False, 'is_paid': True, 'limit': 100, 'skip': 0}
headers = {'content-type': 'application/json'}
response = requests.get(url=url, headers=headers, params=params)
In server side I am receiving all values as string,
how can I make request to get proper boolean values not string one.
To send a json payload use the data
or json
argument instead of params
. Convert the dict to json first using json.dumps
, and double-check the conversion if you like:
import json
payload = json.dumps(params)
print(payload) # '{"is_coming_soon": false, "is_paid": true, "limit": 100, "skip": 0}'
response = requests.get(url=url, headers=headers, data=payload)
Also, you can debug requests
calls like this:
import requests
import logging
from http.client import HTTPConnection
# from httplib import HTTPConnection # Python 2
HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
response = requests.get(url=url, headers=headers, data=payload)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With