Difference between the json and data parameter in python requests library post call

August 4, 2022

Json:

  • requests.post(url, json=payload)
  • str type / dict type
  • headers in content-type becomes application/json
  • converts data into JSON string

Data:

  • requests.post(url, data=payload)
  • dict type
  • headers in content-type becomes application/x-www-form-urlencoded
  • equivalent to ordinary form submission
  • converts data into key value pairs