yongtwang / engineering-python

80 stars 75 forks source link

The api for fixer.io has changed so the program currency.py will no longer work #1

Closed RonFredericks closed 12 months ago

RonFredericks commented 5 years ago

The error message is "download failed" with more info showing that endpoint has changed and now requires the use of an API key given to users who create an account on fixer.io. One version of the API key is for community use and is free.

Updated currency.py that works as of 5/28/2019: currency_updated.py

I have attached my working version of currency.py with the api key left blank (you would insert your key after registering with fixer.io)

currency_updated.zip

Changes made to the 12/31/2017 version of currency.py

I was able to fix my version of currency.py to reflect the new format for fixer.io API. Here are the steps I took: 1) register for the free version of the api to get an API access key 2) include json library import json # replace broken eval(data) from original code 3) change http.request to reflect community access key (community version does not support the &base option) r = http.request('GET', 'http://data.fixer.io/api/latest?access_key=your_api_key', retries=False) # Rates are quoted against the default base (EUR). 4) replace data = eval(data) code with JSON to fix error with "True" data = json.loads(data) 5) add the following lines after the for key, value in self.rates.items() loop, to support both the default EUR base as well as the event where another base is used

Manage default base rate: EUR for free fixer account

    baseIndex = self.comboBox_1.findText(data['base'])
    self.comboBox_1.setCurrentIndex(baseIndex)
    self.comboBox_2.setCurrentIndex(baseIndex)
yongtwang commented 12 months ago

Thank you. Problem solved.