I use requests.api lib to send post request. What I want is to send multidimensional POST data and I always come up short with this code:
import requests
url = 'http://someurl.com';
request_data = {}
request_data['someKey'] = 'someData'
request_data['someKeytwo'] = 'someData2'
request_data['requestData'] = {'someKey3': 'someData3'}
login = requests.post(url, data=login_data)
On the receiving end i get a POST with "requestData" => "someKey3" instead of "requestData" => ["someKey3" => 'someData3']
How do I send the correct POST?
Use the list indexing syntax a_2d_list[x] to get the nested list at index x in a 2D list. Call list. append(object) with this nested list as list and the desired element as object to append an element to the nested list.
In Python, Multidimensional Array can be implemented by fitting in a list function inside another list function, which is basically a nesting operation for the list function. Here, a list can have a number of values of any data type that are segregated by a delimiter like a comma.
2D array in python is a two-dimensional data structure, stored linearly in the memory. This means that it has two dimensions, the rows and the columns and thus it also represents a matrix.
The correct answer for my question is:
import requests
url = 'http://someurl.com';
request_data = {}
request_data['requestData[someKey3]'] = 'someData3'
login = requests.post(url, data=request_data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With