API error Handling

This commit is contained in:
Vivek Teega 2021-08-26 08:03:39 +00:00
parent 22cfc18bb8
commit c53484e8a4

View File

@ -1139,16 +1139,13 @@ def updatePrices():
prices = {}
# USD -> INR
response = requests.get(
f"https://api.exchangeratesapi.io/latest?base=USD&symbols=INR")
response = requests.get(f"https://api.exchangerate-api.com/v4/latest/usd")
try:
price = response.json()
if price['success'] == False:
raise ValueError('API response error')
prices['USDINR'] = price['rates']['INR']
except ValueError:
response = requests.get(
f"https://api.exchangerate-api.com/v4/latest/usd")
f"https://api.exchangeratesapi.io/latest?base=USD&symbols=INR")
try:
price = response.json()
prices['USDINR'] = price['rates']['INR']