I want to pass a randomly generated password to my payload. This is what I have-
import requests
import json
import random
import string
#generate 12 character password
alphabet = string.ascii_letters + string.digits + '!@#%^*()'
newpassword = ''.join(random.choice(alphabet) for i in range(12))
url = "https://www.example.com"
payload = "{\n \"id\": 123,\n \"name\": \"John\",\n \"itemValue\": "+newpassword+" \n}"
headers = {
'Content-Type': 'application/json',
}
response = requests.put(url, headers=headers, data=json.dumps(payload))
print(response.text)
I'm not getting the desired output because it is not taking the new password string correctly. Please advise.