Skip to content
Advertisement

Difference between data and json parameters in python requests package

What is the difference between the data and json parameters in the python Requests package?

It is unclear from the documentation

Does this code:

JavaScript

Note that we convert the dict to JSON here ☝️ !

Do anything different than:

JavaScript

If so, what? Does the latter automatically set the content-type in the header to application/json?

Advertisement

Answer

To answer my own question, it appears my two examples above do the same thing and that using the json parameter does indeed set the content-type in the headers to application/json. In my first example above using the data parameter, the content-type in the headers would need to be set manually.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement