I am trying to call a post request using python where the body is a dictionary in which one parameter has to change based on the values of a list.
The list is as below:
my_list = ['a14mnas','ty6798h']The body for the api call is as below:
api_body = {"Page": 1,"Pages": 3,"Ids": []}I am trying to update the body as:
api_body["Ids"] = my_list[0]which will update the body to
"Ids": ['a14mnas']but I need the value in the list to be enclosed with double quotes as below:
"Ids": ["a14mnas"]The api call takes only list with value enclosed with double quotes. How do I make the value to be in double quotes.
Tried adding '''+ to the string but it gives a single and double quote
'''+ my_list[0] +'''If I use this below code, I am able to get the post request to work just fine:
api_body = {"Page": 1,"Pages": 3,"Ids": ["a14mnas"]}myrequest = requests.post(api_url, headers = headers, data = json.dumps(api_body))Where headers have the authentication token.While looping through the list to update the dict (key: Ids), how do I ensure that it takes the double quote?