0

Error message:

File "C:/Users/artisan/PycharmProjects/API connection/polo.py", line 12, in poloniexapi total = sum([int(num) for num in i["quoteVolume"]]) TypeError: 'float' object is not iterable

import requests
import json, requests
import _json

def poloniexapi(url):
    response = requests.get(url)
    json_obj = json.loads(response.text)

    for i in json_obj:
        print(i["quoteVolume"])

    total = sum([int(num) for num in i["quoteVolume"]])

poloniexapi("https://poloniex.com/public?command=returnChartData&currencyPair=BTC_XMR&start=1405699200&end=9999999999&period=86400")

Appreciate all help :)

1 Answer 1

2

for num in i['quoteVolume'] is trying to iterate over i['quoteVolume']. But this is just one number (the last number from the previous for loop), not a list. I think what you want is:

total = sum([int(i["quoteVolume"]) for i in json_obj])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.