Python uses requests POST to submit multiple values for the same key

Python uses requests POST to submit multiple values ​​for the same key

question

When I want to use POST to submit data, I find that the form data submitted by the website is the same key with different values, as shown in the figure below:
insert image description here

requests.post(url, data={
    
    'experiment_id[]':'data1','experiment_id[]':'data2', ...})

It is definitely wrong to use this method, because the key in the dictionary is unique.

Solution

Use a list of tuples

import requests
r = requests.post(url, data=[('experiment_id[]', 'data1'), ('experiment_id[]', 'data2'), ...])

solve!

Guess you like

Origin blog.csdn.net/a6661314/article/details/129029338