How to retrieve data from own node?

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.

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.

Check details on this page:

Yep. I tried that, I get the following error: algosdk.error.AlgodHTTPError: Invalid API Token

Make sure you put the token in the header. Can you share how’d you make the request?

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)

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)
1 Like

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.

Check the source code here:

Thanks, this worked! Appreciate the responses!