1

I got confused between the data and params in requests.session class. What is the difference between data and params?. When do we need to use it and what will be the output difference?

http://docs.python-requests.org/en/latest/api/#requests.Session.request

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
GoT
  • 530
  • 1
  • 13
  • 35

1 Answers1

2

params attaches the parameters to the URL, for a GET request, e.g.:

http://www.example.com/page.php?param1=value1&param2=value2

data, however, adds the (encoded) data to the request body, as in a POST request, so the values do not show up in the URL. This request may then look like:

POST /page.php HTTP/1.0
Host: www.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

param1=value1&param2=value2
hlt
  • 6,219
  • 3
  • 23
  • 43