I call an exchange API. When I try to put it as a function, it returns None
:
def getCurrentExchange(source, target):
"""The function takes the source - source and target currency - target and extract the rate as of now"""
url = 'https://api.exchangerate.host/convert?from=source&to=target'
response = requests.get(url)
data = response.json()
xchng = data['result']
return xchng
print(getCurrentExchange("EUR", "USD"))
When I call the API without wrapping it as a function, I get the rate:
url = 'https://api.exchangerate.host/convert?from=USD&to=EUR'
response = requests.get(url)
data = response.json()
data['result']
What am I doing wrong?