tscizzle tscizzle - 2 months ago 6
Python Question

Difference between "data" and "params" in Python requests?

I was curious what the difference was between the

parameter and the
parameter in a
request, and when each should be used.

One example is I have an array of dicts
users=[{"email_hash": "fh7834uifre8houi3f"}, ... ]
and I try to do a POST (
) with

params = {
"ads_token": blah blah,
"user_id": blah blah,
"users": json.dumps(users) # users=[{"email_hash": "fh7834uifre8houi3f"}, ... ]
"hash_type": "md5"

and because
is a few hundred long, the resulting string from
(and thus the URL itself as well) is very long and I get the error
{'status_code': 414, 'reason': 'Request-URI Too Large'}
. Would this be a case for
or is there some other path I should follow? Thanks!


params form the query string in the URL, data is used to fill the body of a request (together with files). GET and HEAD requests have no body.

For the majority of servers accepting a POST request, the data is expected to be passed in as the request body.

You need to consult the documentation for the specific API you are calling as to what they expect, but if you have to assume, assume you have to use data.