Jake Strouse
Jake Strouse

Reputation: 58

How to send a payload with python requests

So I understand the concept of sending payloads with requests, but I am struggling to understand how to know what to send.

for example, payload = {'key1': 'value1', 'key2': 'value2'} is the payload, but how do I find what key1 is? Is it the element ID? I have worked closely to selenium and I am looking at requests at a faster alternative.

Thanks for your help, Jake.

Upvotes: 1

Views: 1645

Answers (1)

engineercoding
engineercoding

Reputation: 832

Requests is a library which allows you to fetch URL's using GET, POST, PUT, etc requests. On some of those you can add a payload, or extra data which the server uses to do something.

So the payload is handled by the server, but you have to supply them which you do by defining that dictionary. This is all dependent on what the server expects to receive. I am assuming you read the following explanation:

Source

You often want to send some sort of data in the URL’s query string. If you were constructing the URL by hand, this data would be given as key/value pairs in the URL after a question mark, e.g. httpbin.org/get?key=val. Requests allows you to provide these arguments as a dictionary of strings, using the params keyword argument. As an example, if you wanted to pass key1=value1 and key2=value2 to httpbin.org/get, you would use the following code:

>>> payload = {'key1': 'value1', 'key2': 'value2'}
>>> r = requests.get('https://httpbin.org/get', params=payload)

The payload here is a variable which defines the parameters of a request.

Upvotes: 1

Related Questions