I'm getting the following error while trying to execute my script
]""".format(id="123", name="test")
KeyError: '\n "id"'
Here's my script. I just need to format a multiline string. I tried using a dictionary in the format section but that didn't work either.
import requests
payload = """[
{
"id":{id},
"name": "{name}"
}
]""".format(id="123", name="test")
headers = {"Content-Type": "application/json"}
r = requests.post("http://localhost:8080/employee", data=payload,
headers=headers)
print(r.status_code, r.reason)
jsonmodule to avoid problems. In fact,requestscan do that for you. Don't try and format a json string yourself."""[\n {{\n "id"...\n }}\n]""".