'Change value(variable) in URL after adding URL [closed]

I have a URL with variables, and I need to change variables after initiating URL for example

key = ""
secret = ""
url = "http://127.0.0.1:5000/data?key={key}&secret={secret}".format(key=key, secret=secret)
key= "bbb"
print(url)

but I get a blank result, only works when I add value before initiating the URL

<<<http://127.0.0.1:5000/data?key=&secret=



Solution 1:[1]

I think you can have two variables, one to store the unformatted string http://127.0.0.1:5000/data?key={key}&secret={secret} ( url_template in the below code) and one to store the result of the url once the value of key (url in the below code) is obtained

key = ""
secret = ""
url_unformatted = "http://127.0.0.1:5000/data?key={key}&secret={secret}"
key= "bbb"
url = url_unformatted.format(secret=secret, key=key)
print(url)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1