Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

String Indices Must be Integers – Fetching data from API

Here is the data i want to get from

import json

url = "https://api.opensea.io/api/v1/collection/elonpunkyachtclub/stats"

headers = {"Accept": "application/json"}

response = requests.request("GET", url, headers=headers)
data = response.json
decoded = json.loads(data)

{
  "stats": {
    "one_day_volume": 3.4598559686941988,
    "one_day_change": -0.26082160690977335,
    "one_day_sales": 167,
    "one_day_average_price": 0.020717700411342507,
    "seven_day_volume": 24.111522658583088,
    "seven_day_change": 60.74608045431068,
    "seven_day_sales": 1284,
    "seven_day_average_price": 0.01877844443814882,
    "thirty_day_volume": 24.502017447583082,
    "thirty_day_change": 0,
    "thirty_day_sales": 1370,
    "thirty_day_average_price": 0.017884684268308818,
    "total_volume": 24.50201744758308,
    "total_sales": 1370,
    "total_supply": 6969,
    "count": 6969,
    "num_owners": 1854,
    "average_price": 0.017884684268308818,
    "num_reports": 4,
    "market_cap": 130.86697928945915,
    "floor_price": 0.022
  }
}

print(data)
print(data['stats']['floor_price'])

I want to fetch the floor price from the data

Getting error, what I am doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help is appreciated, thanks…….

>Solution :

From the error, it seems that you are operating on a string, not decoded data. Try decoding first:

import json

# ... get data

decoded = json.loads(data)
print(decoded['stats']['floor_price'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading