Fredapi error using get_series method from fredapi package

Hello, fredapi package is succesfully installed in my environment. Importing fredapi and creating the fred object using my api key works. However, when actual pulling data using get_series I get an error. I don’t get this error using other platforms (like datacamp notebook).

import fredapi as Fred
fred=Fred(api_key='some number')
sp500=fred.get_series('SP500') #pull sp500 prices

this is the error I get

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_12768\3735180914.py in <module>
      1 fred = Fred(api_key='48687714d90448d876bb115d06578128')
----> 2 fred.get_series('SP500')

~\anaconda3\envs\my_models\lib\site-packages\fredapi\fred.py in get_series(self, series_id, observation_start, observation_end, **kwargs)
    133             raise ValueError('No data exists for series id: ' + series_id)
    134         data = {}
--> 135         for child in root.getchildren():
    136             val = child.get('value')
    137             if val == self.nan_char:

AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getchildren'

Any idea what is causing this? Thank you.

It appears that Fred is using an old API for elementree. The getchildren method was deprecated in Python 3.2 and removed in Python 3.9: xml.etree.ElementTree — The ElementTree XML API — Python 3.8.16 documentation

Thank you Glen!

So what does this mean exactly? I should use and older version of Python in my local environment if I want to use Fred on my local machine?

But my online notebook on Datacamp can use the Fred package without problems. I presume this online notebook uses the latest Python version. Yet it works.

Thanks again. Appreciate you helping me out.

You need to use a version of Python that is 3.9 or older wherever you want to use Fred.

As to your Datacamp: Did you check or are you just guesssing?

1 Like