from urllib.request import Request, urlopen
import json
# Identify your application explicitly when calling the API.
request = Request("https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP", headers={"User-Agent": "exchangerate-docs/1.0"})
with urlopen(request, timeout=10) as response:
data = json.load(response)
print(data["rates"]["EUR"])
const response = await fetch("https://api.exchangerate.dev/v1/latest/USD?symbols=EUR,GBP", {
signal: AbortSignal.timeout(10_000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
console.log(data.rates.EUR);