Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

f string formatting: Invalid format Specifier

Tags:

python

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.

like image 575
bigalbunyan Avatar asked Apr 09 '26 04:04

bigalbunyan


1 Answers

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}}}'
like image 174
gph Avatar answered Apr 10 '26 17:04

gph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!