3

I'm trying to pass the following data into POST request:

data = {
    "To": MY_PHONE_NUMBER,
    "From": TWILIO_PHONE_NUMBER,
    "Parameters": f'{"appointment_time":{apointment_time}, "name":{name_var}, "age":{age_var}}',
}

I'm getting the following error:

"Parameters": f'{"appointment_time":{apointment_time}, "name":{name_var}, "age":{age_var}}',
ValueError: Invalid format specifier

I've tried using .format as well with no luck.

2 Answers 2

12

In an f string it interprets the brace as preceding a variable. The braces you included for formatting are confusing the parser. Use two braces to escape it.

"Parameters": f'{{"appointment_time":{apointment_time}, "name": {name_var}, "age":{age_var}}}'
-1

You have an extra } character at the end of your code near ``age_var` variable:

"Parameters": f'{"appointment_time":{apointment_time}, "name":{name_var}, "age":{age_var}}',

It should be:

"Parameters": f'{"appointment_time":{apointment_time}, "name":{name_var}, "age":{age_var}',

You should remove it to work.

Not the answer you're looking for? Browse other questions tagged or ask your own question.