JSON有效内容的Python字符串串联

问题描述

我正在尝试修改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'))

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)