pythonfixer.io

KeyError ['date'] - Python fixer.io


I'm starting over with fixerio, I have this code:

import requests
import json

url = "http://api.fixer.io/latest?base=USD"

response = requests.get(url)
data = response.text
parsed = json.loads(data)
date = parsed["date"]
print("Date:", date, "\n")

rates = parsed["rates"]

for currency, rate in rates.items():
    print(currency, "= USD", rate)

Every time I run it, it throws:

C:\usio>python fixerio.py
Traceback (most recent call last):
File "fixerio.py", line 9, in <module>
    date = parsed["date"]
KeyError: 'date'

Problem is, I don't get how can I "declare" this date thing, I mean, it obviously lacks some kind of declaration.

Also, talking about fixer.io, do You think is better with the requests module approach?

Or should the fixerio python module be used?

PS = I'm using python 2.7


Solution

  • Quick print of the output shows that the api is broken

    import requests
    import json
    
    url = "http://api.fixer.io/latest?base=USD"
    
    response = requests.get(url)
    data = response.text
    parsed = json.loads(data)
    print(parsed)
    

    {'0': '#################################################################################################################################', '1': '#