I am working with a cryptocurrency exchange API and I am stuck on trying to get it to pull just the symbol and last from the list from the API. I found many solutions if the list was in the code itself, but I am having trouble pulling from the API then just the two desired items, fields, whatever you would like to call it, but when checking for keys I get None. I have tried many methods found on this site and tutorials by others, but keep running into errors. Here is my code to talk to the API:
def pull():
r = requests.get('API_ADDRESS')
data = r.json()
print(type(data)) # confirms type is list
output: class 'list'
Here is a small chunk from the API URL from the beginning/top of the page via browser:
[{"ask":"0.00000019438","bid":"0.00000019436","last":"0.00000019437","open":"0.00000017778","low":"0.00000017500","high":"0.00000020000","volume":"215392000","volumeQuote":"39.177612838","timestamp":"2019-03-12T22:54:35.168Z","symbol":"BCNBTC"},{"ask":"3886.77","bid":"3886.76","last":"3886.76","open":"3868.90","low":"3814.66","high":"3903.39","volume":"33598.51324","volumeQuote":"129840974.9750335","timestamp":"2019-03-12T22:55:44.772Z","symbol":"BTCUSD"},{"ask":"0.023432","bid":"0.023403","last":"0.023404","open":"0.021257","low":"0.021208","high":"0.023639","volume":"78033.270","volumeQuote":"1720.630098144","timestamp":"2019-03-12T22:55:38.179Z","symbol":"DASHBTC"},
Per the API documentation using curl is how to pull the data so I wonder if I am pulling it down the wrong way and that is part of the issue? The full list is all the currencies supported starting with a [ and ending with a ], each currency open and closes with {}.
I have been working with APIs like this that are dicts and have keys with no problem:
{
'items':[
{
'created_on':'2016-11-08',
'etag':'DELETED',
'classification':{
'type':'charge-description',
'description':'A registered charge'
I wuld like to pull in order just the symbol, last. The only way I have been able to get the symbol or last to print is add [0] in front, but then only prints the first entry of the list. I am just learning Python so I am not sure the best way to complete this task without having extra code or redundant code. I want to keep this as clean as possible. I already used the above core code to talk to another API that is a dict and starts with results: = so it was quite easy to pull the data I want, but this is the first API JSON list i have tried using so I need a little help so I can learn from this challenge.
I did try: python getting a list of value from list of dict
But the all lists are in the code itself and not a list being pulled from an API. As another option i moved away from requests to pycurl and now when checking type it shows as:
<class 'bytes'>
After much more research i found a solution and posted my new working code below as a answer.