URL Error Connection Refused

I posted an issue on GitHub for this problem as well. I am receiving the following error working through an ASA Tutorial.

(algoenv) Brians-MacBook-Pro:create-layla-coin brianhaney$ python3 run.py
b'O\x88\xfd\xf2\xd1\xfe\xee\x96+\xf9\xf0\xb6\xb2\x8d\r\xb5\xced)#\x9bV\xce\xa4\x81\xa6\xb9\xbd\x0e\xf7al'
b'T4j98tH+7pYr+fC2so0Ntc5kKSObVs6kgaa5vQ73YWw='
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 928, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "run.py", line 18, in <module>
    create(creator_passphrase)
  File "/Users/brianhaney/node/algorand-tutorials-python/create-layla-coin/main.py", line 16, 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 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 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  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 1345, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 61] Connection refused>

The error is coming from running a run.py file, which includes the code from the last part of Part 3 in the Tutorial:

from main import create
from config import creator_passphrase
create(creator_passphrase)

I think the problem is that my node is connecting to testnet-v1.0 because the code was successfully built for and implemented on testnet-v1.5.

I attempted to solve this problem by updating the testnet according to the following Issue on Github. However, my node is still stuck on testnet-v1.0. I also tried switching the genesis.json file from the testnet to the devnet, but my node is still running on testnet-v1.0. Moving forward, I am hacking toward a solution to allow my node to connect to the appropriate network to solve the connection error. I would appreciate any advice or suggestions, thanks!

The genesis ID of testnet will always be testnet-v1.0. There is no testnet-v1.5.

The issue is most likely that your algod url or token is incorrect.
Can you show your file /Users/brianhaney/node/algorand-tutorials-python/create-layla-coin/main.py? In particular, how you create your algod client.

You can use:

algod_address = "https://testnet.algoexplorerapi.io"
client = algod.AlgodClient("", algod_address, headers={'User-Agent': 'DoYouLoveMe?'})
1 Like

Thanks so much for your help @fabrice. I updated my main.py file, which you can view on GitHub. Specifically, I added the following line:

client = algod.AlgodClient("", algod_address, headers={'User-Agent': 'DoYouLoveMe?'})

I also updated the algod_address in the config.py file, such that:

algod_address = "https://testnet.algoexplorerapi.io"

Now, I am getting a new error:

(algoenv) Brians-MacBook-Pro:create-layla-coin brianhaney$ python3 run.py
b'O\x88\xfd\xf2\xd1\xfe\xee\x96+\xf9\xf0\xb6\xb2\x8d\r\xb5\xced)#\x9bV\xce\xa4\x81\xa6\xb9\xbd\x0e\xf7al'
b'T4j98tH+7pYr+fC2so0Ntc5kKSObVs6kgaa5vQ73YWw='
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1317, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1392, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "run.py", line 18, in <module>
    create(creator_passphrase)
  File "/Users/brianhaney/node/algorand-tutorials-python/create-layla-coin/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 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 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  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 1360, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>

This still seems to be a URL Error, relating to Network connectivity.

This problem has been solved. I launched DogCoin to the TestNet.

I needed to update my Python certificates. Running the following from the command line resolved the Issue.

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

Thanks so much @fabrice and @liz for your help!