I am making an API call in my flask app:
count = len(bankid)
bankid = "044"
response = requests.get(f"{base_api_url}/banks/" + "{bankid}/branches".format(bankid=f"{{{bankid}:0{count}d}}", headers=headers))
My target is to use this url https://api.flutterwave.com/v3/banks/044/branches
. Passing in "044" string only removes the leading zero
so trying to use python string formatting to pass in {044:03d}
.
This is what I get:
GET /v3/banks/%7B044:03d%7D/branches HTTP/1.1" 401 65]
I want:
GET /v3/banks/044/branches HTTP/1.1" 401 65]
I want python to use "{}" rather than the unicode representation.
There's no point of having
bankId
astring
and then tell fstring to treat it asint
just to enforce formatting that would produce it back in the form of original string. You are simply over-complicating the way you construct target URL:EDIT
Then you should have make it clear in your question first. Anyway, the change is trivial, just create string form of
bankId
as you like prior using it: