5

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?

3
  • There is no such thing as a "multidimensional POST"; requests are always linear. Are you trying to emulate how another specific language/library arranges a request? Commented Nov 5, 2015 at 10:08
  • Maybe you should post your whole structure as JSON? Commented Nov 5, 2015 at 10:10
  • answered my own question. languages like php contain $_POST data in multidimensional arrays and key=> value pairs. I wanted to receive something like $_POST['requestData']['someKey3'] and get "someData3". Commented Nov 5, 2015 at 11:39

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

Comments

1

Simply use:

import json
login = requests.post(rul, data=json.dumps(login_data))

This way you receive a json on the the receiving side.

1 Comment

I don't need to send json. I need to send a POST key => value multidimensional data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.