I am making a currency converter script in Python in Visual Studio Code and I'm using the frankfurter API, it used to work fine about a few days ago until now where everytime I try to fetch the API I get the 404 error:
> response = requests.get(f"https://api.frankfurter.app/latest?amount={amount}&from={CF}&to={CT}")
> print("API Response:", response.json())
> print(response.status_code)
Output:
API Response: {'message': 'not found'}
404
Traceback (most recent call last):
File "C:\Users\OMEN\Visual Studio\RTCurrencyConverter\Converter.py", line 59, in <module>
print(f"{amount} {CF} is {response.json()['rates'][CT]} {CT}")
KeyError: 'rates'
Virtual environments for me have been very inconsistent in general and I kept trying to remove and recreate environments hoping that would fix something but to no avail.
I've tried the api and it works as expected also it does not seem like a problem with the requests from Python3. Below i show some of the cases which might be the problem.
Below is a correct usage with a correct response.
https://api.frankfurter.app/latest?amount=2&from=USD&to=GBP
{"amount":2.0,"base":"USD","date":"2024-07-30","rates":{"GBP":1.5569}}
This one is not a correct usage. See the from
param instead of USD i wrote UST
got us 404 with the same response you got:
https://api.frankfurter.app/latest?amount=2&from=UST&to=GBP
404 {"message":"not found"}
Or it might be if your CF
or CT
params are None like below example.
I sent empty to
param:
https://api.frankfurter.app/latest?amount=2&from=USD&to=
404 {"message":"not found"}
Log your params before sending the request and take a look like below code:
request_url = f"https://api.frankfurter.app/latest?amount={amount}&from={CF}&to={CT}"
print(f"Trying the request \n {request_url}")
response = requests.get(request_url)
print("API Response:", response.json())
print(response.status_code)