WinError 10061 from Algorand

123 Views Asked by At

I use a ready-made code in Algorand, but when I try to run it with my private key and my address I get this exception: urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>

Thanks for the help!

The code

def first_transaction_example(private_key, my_address):
    algod_address = "http://localhost:4001"
    algod_token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    algod_client = algod.AlgodClient(algod_token, algod_address)
    print("My address: {}".format(my_address))
    account_info = algod_client.account_info(my_address)
    print("Account balance: {} microAlgos".format(account_info.get('amount')))

1

There are 1 best solutions below

0
On

This error indicates that no Algorand node is running and accessible via http://localhost:4001.

First check that you are running a node successfully (and on the same machine as the one used to run the Python script). If you are using sandbox, you can run ./sandbox status to check sandbox status. It should look like:

$ ./sandbox status

algod - goal node status
WARN[0000] The "INDEXER_ENABLE_ALL_PARAMETERS" variable is not set. Defaulting to a blank string.
Last committed block: 10
Time since last block: 0.2s
Sync Time: 0.0s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/d5ac876d7ede07367dbaa26e149aa42589aac1f7
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/d5ac876d7ede07367dbaa26e149aa42589aac1f7
Round for next consensus protocol: 11
Next consensus protocol supported: true
Last Catchpoint:
Genesis ID: sandnet-v1
Genesis hash: XRZ2psvQVPzwuKhTOsSAB9HSUxhMja/tH1RXZvn0EQ4=

indexer - health
{
  "data": {
    "migration-required": false,
    "migration-status": "Migrations Complete"
  },
  "db-available": true,
  "is-migrating": false,
  "message": "7334",
  "round": 7334,
  "version": "(unknown version)"
}

You can also check if no firewall is blocking anything by running

$ curl "localhost:4001/v2/status?pretty" -H "X-Algo-API-Token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -v
*   Trying 127.0.0.1:4001...
* Connected to localhost (127.0.0.1) port 4001 (#0)
> GET /v2/status?pretty HTTP/1.1
> Host: localhost:4001
> User-Agent: curl/7.84.0
> Accept: */*
> X-Algo-API-Token: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=UTF-8
< Vary: Origin
< Date: Thu, 04 Aug 2022 22:33:33 GMT
< Content-Length: 628
<
{
  "catchpoint": "",
  "catchpoint-acquired-blocks": 0,
  "catchpoint-processed-accounts": 0,
  "catchpoint-total-accounts": 0,
  "catchpoint-total-blocks": 0,
  "catchpoint-verified-accounts": 0,
  "catchup-time": 0,
  "last-catchpoint": "",
  "last-round": 22,
  "last-version": "https://github.com/algorandfoundation/specs/tree/d5ac876d7ede07367dbaa26e149aa42589aac1f7",
  "next-version": "https://github.com/algorandfoundation/specs/tree/d5ac876d7ede07367dbaa26e149aa42589aac1f7",
  "next-version-round": 23,
  "next-version-supported": true,
  "stopped-at-unsupported-round": false,
  "time-since-last-round": 567674760
}
* Connection #0 to host localhost left intact

Finally, you can switch to use API services instead of a localhost node. See https://developer.algorand.org/ecosystem-projects/?tags=api-services