How to pass an environment variable in the URL in python script component?

I used the below code and it doesn't seem to work.

 

response = requests.get('''https://api.name.com/?type=sometype&key="${API_KEY}"&limit=10&columns=a,b,c,d&domain=somedomain.com&database=abc''')

 

But when I hardcode the API key in the URL, it works

 

Can someone help me with where I'm doing this wrong?

 

Thanks in advance!

When I reference variables in python I don't wrap it in the ${}. So you could try

 

response = requests.get('''https://api.name.com/?type=sometype&key="API_KEY"&limit=10&columns=a,b,c,d&domain=somedomain.com&database=abc''')

 

and see if that solves your issue. But personally I would build my URL into a variable and pass that into the requests.get instead of trying to do it all in one line. Plus that makes it easier to debug as you can print the variables and make sure they are being read/generated correctly.