my code is

from forex_python.converter import CurrencyRates

forex = CurrencyRates.get_rates('USD', 'EUR')
print(forex)

the error I get is the following:

 File "/Users/asjbentley/opt/anaconda3/lib/python3.7/site-packages/forex_python/untitled0.py", line 12, in <module>
    forex = CurrencyRates.get_rates('USD', 'EUR')

  File "/Users/asjbentley/opt/anaconda3/lib/python3.7/site-packages/forex_python/converter.py", line 55, in get_rates
    date_str = self._get_date_string(date_obj)

AttributeError: 'str' object has no attribute '_get_date_string'

I have done the pip install of the package. The function the error is referring to is in their package. This is a simple script which I should have no issues running.

2

There are 2 best solutions below

0
On

Looking at the source code, get_rates is a function that accepts a base_cur as first argument and a date_obj as second argument. So if you pass a str to the second argument, it'll try to use a datetime.datetime object and it'll throw the error.

Maybe you meant get_rate, with base_cur as first argument and dest_cur as second argument (both strs)?

0
On

from datetime import date from forex_python.converter import CurrencyRates

#Utilisez la date actuelle current_date = date.today()

#Appel de la méthode get_rates avec un objet de date forex = CurrencyRates()

rates = forex.get_rates('USD', 'EUR', date_obj=current_date)