How to retrieve data from own node? - General - Algorand
How to retrieve data from own node?
post by jasl on Jan 8, 2022
If I run algod, I see something like: Node running and accepting RPC requests over HTTP on port 127.0.0.1:8080. Press Ctrl-C to exit
However, when I try something like: http://127.0.0.1:8080/v2/assets/312769, I see {\"message\":\"Invalid API Token\"}. What API token am I supposed to use and where do I put it when I am sending this request?
If I send a request like: http://127.0.0.1:8080/genesis, I am able to receive back a response, but any request I send to get an account or asset info, I see the “invalid api token”… Any help would be appreciated.
post by meowking on Jan 9, 2022
Under your node/data folder, you should be able to find a algod.token file, the content will be the token you need to pass in the header’s X-Algo-API-Token field.
post by jasl on Jan 11, 2022
Yep. I tried that, I get the following error: algosdk.error.AlgodHTTPError: Invalid API Token
post by meowking on Jan 11, 2022
Make sure you put the token in the header. Can you share how’d you make the request?
post by jasl on Jan 11, 2022
from algosdk.v2client import algod
algod_address = "http://localhost:8080"
algod_token = ""
headers = {
"X-Algo-API-Token": 'token_here'
}
algod_client = algod.AlgodClient(algod_token, algod_address, headers)
asset = algod_client.asset_info(312769)
print(asset)
post by meowking on Jan 11, 2022
According to the doc here:
https://py-algorand-sdk.readthedocs.io/en/latest/algosdk/algod.html
if you are passing the algod_token in AlgodClient, you don’t need to pass the headers:
Try this:
from algosdk.v2client import algod
algod_address = "http://localhost:8080"
algod_token = "here put the token you copied from node/data/algod.token file"
algod_client = algod.AlgodClient(algod_token, algod_address)
asset = algod_client.asset_info(312769)
print(asset)
post by meowking on Jan 11, 2022
If you pass the first parameter algod_token as empty string, and pass the headers too, your token will be overwritten by the algod_token value, which in your case, it will be an empty string again.
post by jasl on Jan 19, 2022
Thanks, this worked! Appreciate the responses!