Hello
I have written a python script, which calls the API of ethermine.org, I then use this script in my telegraf config to send the data to influxdb. My first API call worked fine, however, I am having some trouble with a formatting issue I think with another call, have been trying for a few hours, but am making little headway. I will link a question I asked on stack overflow which is regarding the same issue (python - Reformatting a JSON API Response From Ethermine.org - Stack Overflow) I thought I solved the issue, but it doesn’t seem to work. Here is my full python code:
import json
import requests
# Miner - Statistics Altus
keyAltus = '927fC5a85304eB3c181e27971B284c625D3cBbE9'
urlAltus = 'https://api.ethermine.org/miner/' + keyAltus + '/currentStats'
# PoolStats
urlPoolStats = 'https://api.ethermine.org' + '/poolStats'
statsAltus = requests.get(urlAltus)
statsPool = requests.get(urlPoolStats)
json_statsAltus = json.dumps(statsAltus.json()['data'])
print(json_statsAltus)
json_statsPool = json.dumps(statsPool.json()['data'])
print(json_statsPool)
Here is the output of the python script:
{"time": 1614606000, "lastSeen": 1614605949, "reportedHashrate": 36529025, "currentHashrate": 41833333.333333336, "validShares": 37, "invalidShares": 0, "staleShares": 1, "averageHashrate": 35104166.66666665, "activeWorkers": 1, "unpaid": 6540063810106981, "unconfirmed": null, "coinsPerMin": 1.222612368565292e-06, "usdPerMin": 0.0018655964393174647, "btcPerMin": 3.897688230986151e-08}
{"topMiners": [], "minedBlocks": [{"number": 11952655, "miner": "3b1964b93e16e16dc4b29b8a43c456089e60666f", "time": 1614606357}, {"number": 11952653, "miner": "68e9c48084e0bb60f454bb007d9058870ad71e6a", "time": 1614606296}, {"number": 11952650, "miner": "58f1Ea8Ae31878157aE2D54D4A68A3b87ea21Fa7", "time": 1614606259}, {"number": 11952646, "miner": "67e3dD6e50901cA1d60f63c91c142622b4D7015E", "time": 1614606179}, {"number": 11952632, "miner": "8d3966B04B1Cba40598526aC53B46B72281A9f87", "time": 1614605982}, {"number": 11952631, "miner": "80f77e45fb17870A030a8f631de444e2218b555b", "time": 1614605950}, {"number": 11952630, "miner": "93b94364845A31D960002962125880b6DE15f5eA", "time": 1614605943}, {"number": 11952627, "miner": "aa9f1b772b9a5f64629ba1a44899cefdbd6466b1", "time": 1614605938}, {"number": 11952617, "miner": "fdeb381e8c65521674897562916a368fc418a4ff", "time": 1614605839}, {"number": 11952612, "miner": "01139F82659A3bD56D1f051D57D4Bc96a3b9Ef05", "time": 1614605733}], "poolStats": {"hashRate": 83758921222213.8, "miners": 170498, "workers": 518508, "blocksPerHour": 58.17}, "price": {"usd": 1525.91, "btc": 0.03188}}
Using https://jsonlint.com/ both of them are valid JSON, so I don’t quite understand why the first print(ie the one that starts with {“time”} works, but then when I add the second one I get an error like the following:
2021-03-01T14:07:29Z E! [inputs.exec] Error in plugin: invalid character '{' after top-level value
2021-03-01T14:07:29Z E! [telegraf] Error running agent: input plugins recorded 1 errors