Failed to establish a new connection: [Errno 111] Connection refused #582
Description
Error Code
from web3 import Web3
#for connecting to ganache
w3 = Web3(Web3.HTTPProvider("HTTP://0.0.0.0:7545"))
chain_id = 5777
my_address = "0x8f0985D97A8C4f5D5e114bD620e9BEa8ed31FF4e"
private_key = "15e5dbb03aca0d5de6a79c759516b78620e9fad2f730c56e4148fa068b0f9221"
#Get the latest transaction
nonce = w3.eth.getTransactionCount(my_address)
print(nonce)
Error
Traceback (most recent call last):
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connection.py", line 174, in _new_conn
conn = connection.create_connection(
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/util/connection.py", line 96, in create_connection
raise err
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/util/connection.py", line 86, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connection.py", line 239, in request
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
File "/usr/lib/python3.8/http/client.py", line 1252, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1298, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1247, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1007, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 947, in send
self.connect()
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connection.py", line 205, in connect
conn = self._new_conn()
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connection.py", line 186, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fc33ceefca0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='0.0.0.0', port=7545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc33ceefca0>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 10, in
nonce = w3.eth.getTransactionCount(my_address)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/manager.py", line 197, in request_blocking
response = self._make_request(method, params)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/manager.py", line 150, in _make_request
return request_func(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/gas_price_strategy.py", line 90, in middleware
return make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/attrdict.py", line 33, in
middleware
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/formatting.py", line 76, in apply_formatters
response = make_request(method, params)
File "cytoolz/functoolz.pyx", line 250, in cytoolz.functoolz.curry.call
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/formatting.py", line 74, in apply_formatters
response = make_request(method, formatted_params)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/buffered_gas_estimate.py", line 40, in middleware
return make_request(method, params)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/middleware/exception_retry_request.py", line 105, in middleware
return make_request(method, params)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/providers/rpc.py", line 88, in make_request
raw_response = make_post_request(
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/web3/_utils/request.py", line 48, in make_post_request
response = session.post(endpoint_uri, data=data, *args, **kwargs) # type: ignore
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/requests/sessions.py", line 590, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/mnt/c/Users/User/demos/web3_py_simple_storage/venv/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=7545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc33ceefca0>: Failed to establish a new connection: [Errno 111]
Connection refused'))