Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send multidimensional POST in Python

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?

like image 495
drakonli Avatar asked Sep 26 '22 07:09

drakonli


People also ask

How do you append to a multidimensional list in Python?

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.

How does Python handle multidimensional arrays?

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.

Does Python have 2 dimensional arrays?

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.


1 Answers

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)
like image 96
drakonli Avatar answered Sep 30 '22 07:09

drakonli