I need to send nested request. Here is example of dict:
data = {
"customer_id": "customer_1",
"time": get_timestamp(),
"data_1": ["1", "2"],
"data_2": ["6", "7"],
}
There can be larger amount of elements in lists and more lists, this is just an example.
When sending r = requests.post(url, data=data)
or r = requests.post(url, json=data)
or r = requests.post(url, data=json.dumps(data))
I get a validation message that there a no required fields and I checked that data hasn't been sent. However, if I send it like this it works:
data = {
"customer_id": "customer_1",
"time": get_timestamp(),
"data_1[0]": "1",
"data_1[1]": "2",
"data_2[0]": "6",
"data_2[1]": "7"
}
Is there a way to send lists using requests without having to put every element as different key?
Edit. I forgot to mention that I need to send files together too. At first I hasn't thought that files can be a problem, but they of course can (I wanted to simplify question as much as possible). I add files: files = {"files": open(path_to_file, "rb")}
and send adding files=files
to POST request. So the whole code would look like this:
url = ""
token = "token"
headers = {"Authorization": "Bearer " + token}
data = {
"customer_id": "customer_1",
"time": get_timestamp(),
"data_1": ["1", "2"],
"data_2": ["6", "7"],
}
path_to_file = "file.jpg"
files = {"files": open(path_to_file, "rb")}
r = requests.post(url, data=data, files=files, headers=headers, verify=False)