我正在尝试修改 Postman 生成的这段代码,以用字符串变量替换硬编码字符串,但我不断收到
KeyError: '\n\t"username"'
这是代码
username = "jose"
email = "some_email"
password = "1234"
url = "some_url"
payload = '{\n\t\"username\": {},\n\t\"email\": {},\n\t\"password\": {}\n}'.format(username, email, password)
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text.encode('utf8'))
Helenr
长风秋雁
相关分类