Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3 ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8545) #1650

Closed
iDataist opened this issue May 15, 2020 · 5 comments
Closed

Comments

@iDataist
Copy link

iDataist commented May 15, 2020

  • Version: 5.9.0
  • Python: Python 3.7.7
  • OS: osx
  • pip freeze output
<alabaster==0.7.12
anaconda-client==1.7.2
anaconda-project==0.8.3
applaunchservices==0.2.1
appnope==0.1.0
appscript==1.0.1
argh==0.26.2
asn1crypto==1.3.0
astroid==2.4.0
astropy==4.0.1.post1
atomicwrites==1.4.0
attrs==19.3.0
autopep8==1.4.4
Babel==2.8.0
backcall==0.1.0
backports.shutil-get-terminal-size==1.0.0
base58==2.0.0
beautifulsoup4==4.9.0
bit==0.6.1
bitarray==1.2.1
bkcharts==0.2
bleach==3.1.4
bokeh==2.0.2
boto==2.49.0
Bottleneck==1.3.2
certifi==2020.4.5.1
cffi==1.14.0
chardet==3.0.4
click==7.1.2
cloudpickle==1.4.1
clyent==1.2.2
coincurve==13.0.0
colorama==0.4.3
contextlib2==0.6.0.post1
cryptography==2.9.2
cycler==0.10.0
Cython==0.29.17
cytoolz==0.10.1
dask==2.16.0
decorator==4.4.2
defusedxml==0.6.0
diff-match-patch==20181111
distributed==2.16.0
docutils==0.16
entrypoints==0.3
et-xmlfile==1.0.1
eth-abi==2.1.1
eth-account==0.5.2
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.3.3
eth-rlp==0.1.2
eth-tester==0.4.0b2
eth-typing==2.2.1
eth-utils==1.9.0
fastcache==1.1.0
filelock==3.0.12
flake8==3.7.9
Flask==1.1.2
fsspec==0.7.1
future==0.18.2
gevent==1.4.0
glob2==0.7
gmpy2==2.0.8
greenlet==0.4.15
h5py==2.10.0
HeapDict==1.0.1
hexbytes==0.2.0
html5lib==1.0.1
hypothesis==5.11.0
idna==2.9
imageio==2.8.0
imagesize==1.2.0
importlib-metadata==1.5.0
intervaltree==3.0.2
ipfshttpclient==0.4.13.2
ipykernel==5.1.4
ipython==7.13.0
ipython-genutils==0.2.0
ipywidgets==7.5.1
isort==4.3.21
itsdangerous==1.1.0
jdcal==1.4.1
jedi==0.15.2
Jinja2==2.11.2
joblib==0.14.1
json5==0.9.4
jsonschema==3.2.0
jupyter==1.0.0
jupyter-client==6.1.3
jupyter-console==6.1.0
jupyter-core==4.6.3
jupyterlab==1.2.6
jupyterlab-server==1.1.1
keyring==21.1.1
kiwisolver==1.2.0
lazy-object-proxy==1.4.3
libarchive-c==2.9
llvmlite==0.32.1
locket==0.2.0
lru-dict==1.1.6
lxml==4.5.0
MarkupSafe==1.1.1
matplotlib==3.1.3
mccabe==0.6.1
mistune==0.8.4
mkl-fft==1.0.15
mkl-random==1.1.0
mkl-service==2.3.0
mock==4.0.2
more-itertools==8.2.0
mpmath==1.1.0
msgpack==1.0.0
multiaddr==0.0.9
multipledispatch==0.6.0
nbconvert==5.6.1
nbformat==5.0.6
netaddr==0.7.19
networkx==2.4
nltk==3.4.5
nose==1.3.7
notebook==6.0.3
numba==0.49.0
numexpr==2.7.1
numpy==1.18.1
numpydoc==0.9.2
olefile==0.46
openpyxl==3.0.3
packaging==20.3
pandas==1.0.3
pandocfilters==1.4.2
parsimonious==0.8.1
parso==0.5.2
partd==1.1.0
path==13.1.0
pathlib2==2.3.5
pathtools==0.1.2
patsy==0.5.1
pep8==1.7.1
pexpect==4.8.0
pickleshare==0.7.5
Pillow==7.1.2
pkginfo==1.5.0.1
pluggy==0.13.1
ply==3.11
prometheus-client==0.7.1
prompt-toolkit==3.0.4
protobuf==3.11.3
psutil==5.7.0
ptyprocess==0.6.0
py==1.8.1
pycodestyle==2.5.0
pycosat==0.6.3
pycparser==2.20
pycrypto==2.6.1
pycryptodome==3.9.7
pycurl==7.43.0.5
pydocstyle==4.0.1
pyflakes==2.1.1
Pygments==2.6.1
pylint==2.5.0
pyodbc===4.0.0-unsupported
pyOpenSSL==19.1.0
pyparsing==2.4.7
pyrsistent==0.16.0
PySocks==1.7.1
pytest==5.4.1
pytest-arraydiff==0.3
pytest-astropy==0.8.0
pytest-astropy-header==0.1.2
pytest-doctestplus==0.5.0
pytest-openfiles==0.5.0
pytest-remotedata==0.3.2
python-dateutil==2.8.1
python-jsonrpc-server==0.3.4
python-language-server==0.31.10
pytz==2020.1
PyWavelets==1.1.1
PyYAML==5.3.1
pyzmq==18.1.1
QDarkStyle==2.8.1
QtAwesome==0.7.0
qtconsole==4.7.4
QtPy==1.9.0
requests==2.23.0
rlp==1.2.0
rope==0.17.0
Rtree==0.9.4
ruamel-yaml==0.15.87
scikit-image==0.16.2
scikit-learn==0.22.1
scipy==1.4.1
seaborn==0.10.1
semantic-version==2.8.5
Send2Trash==1.5.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.14.0
snowballstemmer==2.0.0
sortedcollections==1.1.2
sortedcontainers==2.1.0
soupsieve==2.0
Sphinx==3.0.3
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sphinxcontrib-websupport==1.2.1
spyder==4.1.3
spyder-kernels==1.9.1
SQLAlchemy==1.3.16
statsmodels==0.11.0
sympy==1.5.1
tables==3.6.1
tblib==1.6.0
terminado==0.8.3
testpath==0.4.4
toml==0.10.0
toolz==0.10.0
tornado==6.0.4
tqdm==4.46.0
traitlets==4.3.3
typed-ast==1.4.1
typing-extensions==3.7.4.1
ujson==1.35
unicodecsv==0.14.1
urllib3==1.25.8
varint==1.0.2
watchdog==0.10.2
wcwidth==0.1.9
web3==5.9.0
webencodings==0.5.1
websockets==8.1
Werkzeug==1.0.1
widgetsnbextension==3.5.1
wrapt==1.11.2
wurlitzer==2.0.0
xlrd==1.2.0
XlsxWriter==1.2.8
xlwings==0.19.0
xlwt==1.3.0
yapf==0.28.0
zict==2.0.0
zipp==3.1.0>

What was wrong?

The first two lines worked fine.
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('HTTP://127.0.0.1:8545'))

  • The code which produced the error
    w3.eth.getBalance("0xD498cEb53D2E1b48375e2d1F1a257f5B787C9fD5")

  • The full output of the error

ConnectionRefusedError                    Traceback (most recent call last)
~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/connection.py in _new_conn(self)
    156             conn = connection.create_connection(
--> 157                 (self._dns_host, self.port), self.timeout, **extra_kw
    158             )

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     83     if err is not None:
---> 84         raise err
     85 

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     73                 sock.bind(source_address)
---> 74             sock.connect(sa)
     75             return sock

ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    671                 headers=headers,
--> 672                 chunked=chunked,
    673             )

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    386         else:
--> 387             conn.request(method, url, **httplib_request_kw)
    388 

~/anaconda3/envs/ethereum/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1251         """Send a complete request to the server."""
-> 1252         self._send_request(method, url, body, headers, encode_chunked)
   1253 

~/anaconda3/envs/ethereum/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1297             body = _encode(body, 'body')
-> 1298         self.endheaders(body, encode_chunked=encode_chunked)
   1299 

~/anaconda3/envs/ethereum/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)
   1246             raise CannotSendHeader()
-> 1247         self._send_output(message_body, encode_chunked=encode_chunked)
   1248 

~/anaconda3/envs/ethereum/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)
   1025         del self._buffer[:]
-> 1026         self.send(msg)
   1027 

~/anaconda3/envs/ethereum/lib/python3.7/http/client.py in send(self, data)
    965             if self.auto_open:
--> 966                 self.connect()
    967             else:

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/connection.py in connect(self)
    183     def connect(self):
--> 184         conn = self._new_conn()
    185         self._prepare_conn(conn)

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/connection.py in _new_conn(self)
    168             raise NewConnectionError(
--> 169                 self, "Failed to establish a new connection: %s" % e
    170             )

NewConnectionError: <urllib3.connection.HTTPConnection object at 0x107284ed0>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
~/anaconda3/envs/ethereum/lib/python3.7/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    448                     retries=self.max_retries,
--> 449                     timeout=timeout
    450                 )

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    719             retries = retries.increment(
--> 720                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    721             )

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    435         if new_retry.is_exhausted():
--> 436             raise MaxRetryError(_pool, url, error or ResponseError(cause))
    437 

MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=8545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x107284ed0>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
<ipython-input-6-e15ec7612363> in <module>
----> 1 w3.eth.getBalance("0xD498cEb53D2E1b48375e2d1F1a257f5B787C9fD5")

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/eth.py in getBalance(self, account, block_identifier)
    160         return self.web3.manager.request_blocking(
    161             RPC.eth_getBalance,
--> 162             [account, block_identifier],
    163         )
    164 

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/manager.py in request_blocking(self, method, params, error_formatters)
    147         Make a synchronous request using the provider
    148         """
--> 149         response = self._make_request(method, params)
    150 
    151         if "error" in response:

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/manager.py in _make_request(self, method, params)
    126             self.middleware_onion)
    127         self.logger.debug("Making request. Method: %s", method)
--> 128         return request_func(method, params)
    129 
    130     async def _coro_make_request(

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.curry.__call__()

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/formatting.py in apply_formatters(method, params, make_request, request_formatters, result_formatters, error_formatters)
     73         response = make_request(method, formatted_params)
     74     else:
---> 75         response = make_request(method, params)
     76 
     77     if "result" in response and method in result_formatters:

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/gas_price_strategy.py in middleware(method, params)
     32                     transaction = assoc(transaction, 'gasPrice', generated_gas_price)
     33                     return make_request(method, [transaction])
---> 34         return make_request(method, params)
     35     return middleware

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.curry.__call__()

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/formatting.py in apply_formatters(method, params, make_request, request_formatters, result_formatters, error_formatters)
     71         formatter = request_formatters[method]
     72         formatted_params = formatter(params)
---> 73         response = make_request(method, formatted_params)
     74     else:
     75         response = make_request(method, params)

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/attrdict.py in middleware(method, params)
     31     """
     32     def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
---> 33         response = make_request(method, params)
     34 
     35         if 'result' in response:

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.curry.__call__()

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/formatting.py in apply_formatters(method, params, make_request, request_formatters, result_formatters, error_formatters)
     71         formatter = request_formatters[method]
     72         formatted_params = formatter(params)
---> 73         response = make_request(method, formatted_params)
     74     else:
     75         response = make_request(method, params)

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/normalize_errors.py in middleware(method, params)
     23 ) -> Callable[[RPCEndpoint, Any], RPCResponse]:
     24     def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
---> 25         result = make_request(method, params)
     26 
     27         # As of v1.8, Geth returns errors when you request a

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.curry.__call__()

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/formatting.py in apply_formatters(method, params, make_request, request_formatters, result_formatters, error_formatters)
     73         response = make_request(method, formatted_params)
     74     else:
---> 75         response = make_request(method, params)
     76 
     77     if "result" in response and method in result_formatters:

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.curry.__call__()

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/formatting.py in apply_formatters(method, params, make_request, request_formatters, result_formatters, error_formatters)
     71         formatter = request_formatters[method]
     72         formatted_params = formatter(params)
---> 73         response = make_request(method, formatted_params)
     74     else:
     75         response = make_request(method, params)

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/middleware/exception_retry_request.py in middleware(method, params)
    103             for i in range(retries):
    104                 try:
--> 105                     return make_request(method, params)
    106                 # https://github.com/python/mypy/issues/5349
    107                 except errors:  # type: ignore

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/providers/rpc.py in make_request(self, method, params)
     81             self.endpoint_uri,
     82             request_data,
---> 83             **self.get_request_kwargs()
     84         )
     85         response = self.decode_rpc_response(raw_response)

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/web3/_utils/request.py in make_post_request(endpoint_uri, data, *args, **kwargs)
     32     session = _get_session(endpoint_uri)
     33     # https://github.com/python/mypy/issues/2582
---> 34     response = session.post(endpoint_uri, data=data, *args, **kwargs)  # type: ignore
     35     response.raise_for_status()
     36 

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/requests/sessions.py in post(self, url, data, json, **kwargs)
    576         """
    577 
--> 578         return self.request('POST', url, data=data, json=json, **kwargs)
    579 
    580     def put(self, url, data=None, **kwargs):

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    528         }
    529         send_kwargs.update(settings)
--> 530         resp = self.send(prep, **send_kwargs)
    531 
    532         return resp

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/requests/sessions.py in send(self, request, **kwargs)
    641 
    642         # Send the request
--> 643         r = adapter.send(request, **kwargs)
    644 
    645         # Total elapsed time of the request (approximately)

~/anaconda3/envs/ethereum/lib/python3.7/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    514                 raise SSLError(e, request=request)
    515 
--> 516             raise ConnectionError(e, request=request)
    517 
    518         except ClosedPoolError as e:

ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8545): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x107284ed0>: Failed to establish a new connection: [Errno 61] Connection refused'))
  • What type of node you were connecting to.

Screen Shot 2020-05-15 at 7 47 56 AM

How can it be fixed?

I read other posts that had similar problems, but did not figure out how to fix this. Is there any libraries that need to be updated?

@wolovim
Copy link
Member

wolovim commented May 18, 2020

Hey @iDataist, this could be an issue with how you're running the client you're trying to connect to. What client are you running (e.g., geth, openethereum, etc.) and what command are you using to run it?

@wolovim
Copy link
Member

wolovim commented Jun 18, 2020

Closing since I believe this is a configuration issue (and a month old). Hope you've got it resolved, but please reopen with more details if you still have issues.

@wolovim wolovim closed this as completed Jun 18, 2020
@nanaknihal
Copy link

In case anybody else is having this problem, adding --rpc after geth fixed it for me. --http.address localhost --http.port 8545 also may help

@freaker2k7
Copy link

I also found out that you need to connect via http:// rather than https:// because I don't have a valid cert (as far as I see), and in http:// it works fine (slower, because every connection has to do a handshake, but works).

@BrokedTV
Copy link

Is there a clear solution for this? I'm facing the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants