I'm trying to write a fairly simple requests script in a loop, which I need to pass the list item in as one of the parameters. I've done some reading and understand that f strings require double curly braces instead of single, but it's still not working.
import requests
org_names = ['name 1', 'name 2']
for name in org_names:
values = f"""
{
"name": "{{name}}",
"groupId": "xxxx"
}
"""
headers = {
'Content-Type': 'application/json',
'Authorization': 'xxxxx'
}
response = requests.post('https://xxxx', data=values, headers=headers)
data = response.json()
This gives me the following error
ValueError: Invalid format specifier
I've also tried using format(), as follows:
for name in org_names:
values = """
{
"name": "{{}}",
"groupId": "xxxx"
}
""".format(name)
but this gives me the following error:
KeyError: '\n "name"'