Python SDK V1 errors

I’m still using the Python SDK V1 just to little tests and I get this errors:

  File "/home/pi/.local/lib/python3.7/site-packages/algosdk/algod.py", line 231, in suggested_params
    return self.algod_request("GET", req, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/algosdk/algod.py", line 70, in algod_request
    resp = urlopen(req)
  File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.7/urllib/request.py", line 1345, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

Is this beacuse the deprecated Python SDK V1 has been already dismessed or something else?

1 Like

Where are you trying to connect? The above appears to be the main error which may come from a mismatched URL or port.

I’m getting the same error trying to connect to MainNet with the PureStake API. I tried using both links:

https://mainnet-algorand.api.purestake.io/idx2

and

https://mainnet-algorand.api.purestake.io/ps2

But neither worked.

I tried updating my Python certificates, but I had no luck.

open /Applications/Python\ 3.7/Install\ Certificates.command

I am continuing to get the same url open error.

This is the complete error I am getting.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 72, 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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 77, in algod_request
    raise error.AlgodHTTPError(json.loads(e)["message"], code)
algosdk.error.AlgodHTTPError: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "run.py", line 21, in <module>
    create(creator_passphrase)
  File "/Users/brianhaney/node/Lions/main.py", line 17, in create
    params = client.suggested_params()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/algosdk/v2client/algod.py", line 278, 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 79, in algod_request
    raise error.AlgodHTTPError(e, code)
algosdk.error.AlgodHTTPError: {"message":"Forbidden"}

I tried updating my Python-SDK download.

pip3 install py-algorand-sdk

I am still not sure where the problem is coming from. Any advice or suggestions would be greatly appreciated - thanks!

Give this a shot - api-examples/indexer_example.py at master · PureStake/api-examples · GitHub -

Thanks for the reply. I have no problem connecting to TestNet, I can do that from my node. The problem I am having is connecting to MainNet. I am unable to connect to MainNet from my node because I consistently get URL errors. I tried using PureStake as an alternative, but I got the same errors.

To update the SDK, you need to add the flag --upgrade:

python3 -m pip install py-algorand-sdk --upgrade

The follow code works for me without issue:

import json

from algosdk.v2client import algod

# Setup HTTP client w/guest key provided by PureStake
algod_address = 'https://mainnet-algorand.api.purestake.io/ps2'
algod_token = ""
headers = {
    "X-API-Key": "B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab",
}

algodclient = algod.AlgodClient(algod_token, algod_address, headers)

# get suggested parameters from Algod
params = algodclient.suggested_params()

print(json.dumps(vars(params), indent=2, sort_keys=True))
2 Likes

Thanks @fabrice! You are a great one! I just updated the SDK successfully. I will retry connecting to the MainNet and will edit this reply with my results.

This solved the problem. Thank you!