0

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

NeoVe
  • 3,857
  • 8
  • 54
  • 134

2 Answers2

1

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': '#

Arghya Saha
  • 5,599
  • 4
  • 26
  • 48
1

If you go to the url in your browser you can see they have put up a notice

{
  "0": "#################################################################################################################################",
  "1": "#                                                                                                                               #",
  "2": "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT                                                                                   #",
  "3": "#                                                                                                                               #",
  "4": "# This API endpoint is deprecated and has now been shut down. To keep using the Fixer API, please update your integration       #",
  "5": "# to use the new Fixer API endpoint, designed as a simple drop-in replacement.                                                  #",
  "6": "# You will be required to create an account at https://fixer.io and obtain an API access key.                                   #",
  "7": "#                                                                                                                               #",
  "8": "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/fixerAPI/fixer#readme          #",
  "9": "#                                                                                                                               #",
  "a": "#################################################################################################################################"
}

So the key doesn't exist.

sP_
  • 1,738
  • 2
  • 15
  • 29