AlgoSDK Error: Forbidden

I am working on learning how to rekey addresses to create multi-sig addresses. The basic txn I am using I found in the Docs. The basic function I am using is as follows.

def rekey():
    ADDA = ""
    passphrase = ""
    ADDB = ""
    amount = 0
    params = client.suggested_params()
    txn = PaymentTxn(sender=ADDA,sp=params,receiver=ADDA,amt=amount,close_remainder_to=None,note=None,lease=None,rekey_to=ADDB)
    if passphrase:
        txinfo = sign_and_send(txn, passphrase, client)
        print("Transaction ID Confirmation: {}".format(txinfo.get("tx")))
    else:
        write_to_file([txns], "transfer.txn")

rekey()

However, I am getting an error saying the function is forbidden.

(algoenv) Brians-MacBook-Pro:node brianhaney$ python3 rekey.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 82,in algod_request
    resp = urlopen(req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "rekey.py", line 28, in <module>
    rekey()
  File "rekey.py", line 18, in rekey
    params = client.suggested_params()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 314, in suggested_params
    res = self.algod_request("GET", req, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 89,in algod_request
    raise error.AlgodHTTPError(e, code)
algosdk.error.AlgodHTTPError: Forbidden

I am not sure how to read the error because it appears to have several parts or how to resolve the issue. I think it may have to do with validating the transaction with the passphrase. Additionally, I am unsure whether this will rekey the address to a single or multi-sig account. I read the docs on rekeying, but they only provide examples for goal. I have a lot of problems running goal on my machine and wanted to run the rekey transaction in Python. Any advice or suggestions would be greatly appreciated. Thank you!

Update

I checked to make sure there was Algo in the address I am using and there is 0.4 Algo. I also tried pulling the passphrase variable out of the function and then passing passphrase = None to the function. However, I received the same error.

403 usually indicates either an invalid token or an invalid URL for algod.

Can you show how you create client? (hide the token if any)
Which node are you using?

1 Like

Thanks @fabrice! Here is the client creation.

algod_address = "https://mainnet-algorand.api.purestake.io/ps2"
algod_token = ""
headers = {"X-API-Key": algod_token }
client = algod.AlgodClient(algod_token,algod_address,headers)

As far as the node type, I am unable to tell based on the current node classifications in the docs. But, I think I installed the node from this GitHub repo. I also haven’t done anything to upgrade to a particular type of node nor have I participated in consensus from this node. My intuition is it is a non-relay node.

I changed the URL and token after checking Purestake. The new URL I changed to is below.

algod_address = "https://mainnet-algorand.api.purestake.io/idx2"

After making the change, I ran the function again and got this error.

(algoenv) Brians-MacBook-Pro:node brianhaney$ python3 rekey.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 82, in algod_request
    resp = urlopen(req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "rekey.py", line 26, in <module>
    rekey()
  File "rekey.py", line 18, in rekey
    params = client.suggested_params()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 314, in suggested_params
    res = self.algod_request("GET", req, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 89, in algod_request
    raise error.AlgodHTTPError(e, code)
algosdk.error.AlgodHTTPError: invalid input: unable to parse base32 digest data 'txid': illegal base32 data at input byte 0

Any thoughts or suggestions would be greatly appreciated. Thank you again!

Update

I was able to solve the connection issue with right combination of my token and URL. You were right, @fabrice - thank you!

I’m having this same issue too. Tried test nets and mainnets for indexers and algods. Accounts have testnet tokens and real tokens. I keep getting the same 403 error.

I copied my API Key every which way, even manually typed. Can you speak more to the right combination that worked for you?

Please provide the source code replacing the token by xxxx

This was the combination that worked for me.

algod_address = "https://testnet-algorand.api.purestake.io/ps2" 
algod_token = "" 
headers = {"X-API-Key": algod_token }
algod_client = algod.AlgodClient(algod_token,algod_address,headers)