How to pass a nested params object for post method of requests library in python3?

I want to create a nested object to pass to method as a param. This is my code -

import requests

baseURL = ""
userkey = "secret"
sitekey = "secret"

def create(payload):
    r =, params=payload)

def createCustomPayload(customPayload):
    payloadCommon = {'action': 'create', 'api_key': userkey, 'key': sitekey}
    return payloadCommon

create(createCustomPayload({'entity': 'CustomField', 'json': {'custom_group_id': 'test_16Nov_Voter', 'label': 'Relationship With Guardian',
                                                              'data_type': 'String', 'html_type': 'Radio', 'weight': 7, 'options_per_line': 2, 'option_values': ["Father", "Mother", "Husband", "Other"]}}))

It prints this URL-

It should ideally print this URL-{"custom_group_id":"test_16Nov_Voter","label":"Relationship With Guardian","options_per_line":2,"data_type":"String","html_type":"Radio","weight":7,"option_values":["Father","Mother","Husband","Other"]}

Please help.

Read more here:

Content Attribution

This content was originally published by sandy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: