Python Forum

Full Version: json api data parsing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Having issue with this piece of code, its an api that has json text but its not readable.
in _get_mean_subclass
for prod, v in response_API.item():
Attribute error: 'list' object has no attribute 'item'

response_API = requests.get(
    f"https://api.bestbuy.com/v1/products(manufacturer=canon)?format=json&apiKey={cred.api_key}"
).json()


def _get_mean_subclass(response_API):
    r = defaultdict(list)
    for prod, v in response_API.items():
        # looking for keyword subclass or whatever its called
        r[prod].append(v["subclassId"])
    return {k: mean(v) for k, v in r.items()}


print(_get_mean_subclass(response_API["products"]))