Video Of Day

Breaking News

Data Tools - Dealing Alongside The Fred Https Migration Inwards Python

The FRED Economic Data System provided past times the St. Louis Fed has a programming interface (an API)  which I role to stock the database inward my personal interrogation system. The interface is switching over to role the secure HTTPS protocol (from HTTP), in addition to this agency that code needs to hold upward updated. I role Python to access the database, in addition to I ran into issues. I am similar a shot describing how I worked closed to the problems.

I assume that the reader knows Python; this is non a tutorial on how to role the fred bundle inward Python. (I facial expression that I volition eventually write tutorials on those lines.)

Although I accept done a fair amount of Python programming, I accept non kept upward amongst the changes inward how packages are distributed. I create non know whether at that topographic point was a work amongst only my installation, or at that topographic point is a to a greater extent than full general work amongst the "fred" Python bundle on Python 3.3 (which is no longer the latest version).

The upgrade procedure gave me some odd warnings, but it appeared that it worked.

However, when I tried downloading data, I ran into issues. For example, if I tried "fred.category()", I got an mistake of the next format:
TypeError: can't role a string designing on a bytes-like object
What is happening is that the information is non existence decoded properly inside the fred package. I needed to switch over to using XML encoding. For example, I used "fred.category(xml=True)", it downloads the information properly. The "xml=True" pick should hold upward added to whatever other fred calls.

The work was that my master copy code used the default format, which returned the information every bit a Python dict (dictionary) object. I fixed this past times passing the fred output through the parse() command inward the xmltodict package.
>>> out = fred.category(xml=True)
>>> import xmltodict
>>> out_dict = xmltodict.parse(out)

The entirely divergence from the master copy version was that fields inward the lexicon accept "@" appended inward front end of their labels. There may accept been a way of cleaning that up, but it in all probability would accept required reading some documentation.

(c) Brian Romanchuk 2015

No comments