简体   繁体   中英

Putting a variable into payload python requests

#real one
data = {'recipients' : '['+i+']'}
#one from requests
data = {'recipients' : '["908325719514423328"]'}

Hi, so i am trying to put a variable into the data but every time i try it is giving me {'code': 50109, 'message': 'The request body contains invalid JSON.'} , so i wonder if someone know how to put it in here i already tried data = {'recipients': f'["{i}"]'} but didn't work i tried everything but nothing work, thanks you for helping: :)

The one i am currently trying is the #real one

Use the json= parameter (which takes a dictionary) instead of data= (which takes a string)

r = requests.post(url, json={"key": "value"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM