ValueError in Python: unsupported format character ']' (0x5d)

Question:

QUESTION: Same Error as this
ValueError: unsupported format character ']' (0x5d)
but I can’t seem to find any %

I am running a query in Python env using cur.execute()

with conn.cursor() as cur:
    cur.execute(f"""
   SELECT 
    FirstName,
    Surname,
   FORMAT(TotalHours / NULLIF((ContractHours - RemissionHours), 0) * 100, 'N2') AS [Utilisation %]

   FROM t
   JOIN Staff ON Staff.SID = t.SID

   WHERE (@IncludeLeavers = 'Yes' OR @IncludeLeavers= 'No' AND Staff.IsCurrent = 1)
   
   """,
        params={
          "IncludeLeavers": REPORT_OPTIONS["IncludeLeavers"][0]
        })

Error:

ValueError : unsupported format character ‘]’ (0x5d) at index 511[‘ File "<‘string’>",

on this line
IncludeLeavers": REPORT_OPTIONS["IncludeLeavers"][0]

To provide values to/ initialise the variable @IncludeLeavers, I have initialised it in Options, which need to match the query results.

OPTIONS

Asked By: Zedverse07

||

Answers:

As said by @Sarah,

The issue is the percent character and %] sequence.

Adding another % wherever % was used, fixed the issue. Thanks Sarah.

Answered By: Zedverse07
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.