pact-python icon indicating copy to clipboard operation
pact-python copied to clipboard

Example Consumer tests result in 'connection error'

Open etos opened this issue 6 years ago • 3 comments

The following command(s)

pact = Consumer('Consumer').has_pact_with(Provider('Provider'))
pact.start_service()
atexit.register(pact.stop_service)

Cause the following errors

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=1234): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19f7f4a8>: Failed to establish a new connection: [Errno 111] Connection refused'))

/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.7/site-packages/requests/adapters.py:516: ConnectionError
------------------------------------------------------------------------------ Captured stdout setup ------------------------------------------------------------------------------
 * Tip: There are .env files present. Do "pip install python-dotenv" to use them.
 * Serving Flask app "src.app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
[2019-02-28 00:23:44.728039] INFO: werkzeug: 127.0.0.1 - - [28/Feb/2019 00:23:44] "GET /api/ HTTP/1.1" 200 -
------------------------------------------------------------------------------ Captured stderr setup ------------------------------------------------------------------------------
/root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.7/site-packages/pact/bin/pact/lib/ruby/bin/ruby: line 6: /root/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.7/site-packages/pact/bin/pact/lib/ruby/bin.real/ruby: No such file or directory
------------------------------------------------------------------------------- Captured log setup --------------------------------------------------------------------------------
connectionpool.py          662 WARNING  Retrying (Retry(total=8, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdb2e8>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=7, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdb588>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=6, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdb748>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=5, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdb908>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdbac8>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdbc88>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19fdbe80>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19f7f0b8>: Failed to establish a new connection: [Errno 111] Connection refused')': /
connectionpool.py          662 WARNING  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fed19f7f2b0>: Failed to establish a new connection: [Errno 111] Connection refused')': /

etos avatar Feb 28 '19 00:02 etos

I have the same issue

An1matedDavid avatar Jun 02 '21 19:06 An1matedDavid

Hi, is there any solution to this? I'm also facing the same issue.

abhipsb avatar Jul 15 '21 16:07 abhipsb

I had a working pact consumer test few weeks back but I run into this issue recently with Pact.start_service(). So, I added a firewall inbound exception for port over TCP for localhost:1234, rebooted but it did not work. After struggling for a while I turn off my vpn connection and rebooted again and it started working. Funny thing is one of my colleague has the same problem and we tried the same steps but it did not work for him. For us at least, it seems to be a proxy issue but we have run out of ideas on how to resolve it. Here is the error ...

(G-ENVIRONMENT) PS C:\~\src\tests> nosetests -v --nocapture .\pact\test_consumer.py INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [i386-mingw32] WARN TCPServer Error: Permission denied - bind(2) for "::1" port 1234 WARN TCPServer Error: Permission denied - bind(2) for "127.0.0.1" port 1234 c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in initialize': Permission denied - bind(2) for "127.0.0.1" port 1234 (Errno::EACCES) from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in new' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in block in create_listeners' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:82:in each' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:82:in create_listeners' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/ssl.rb:88:in listen' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:70:in initialize' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:45:in initialize' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/rack-2.1.4/lib/rack/handler/webrick.rb:33:in new' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/rack-2.1.4/lib/rack/handler/webrick.rb:33:in run' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:28:in call' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/run.rb:13:in call' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/lib/pact/mock_service/cli.rb:32:in service' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/command.rb:27:in run' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in invoke_command' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor.rb:392:in dispatch' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/base.rb:485:in start' from c:/g_venv/Lib/site-packages/pact/bin/pact/lib/app/pact-mock-service.rb:15:in `

' Failure: ProxyError (HTTPConnectionPool(host='proxy.myorgname..com', port=8080): Max retries exceeded with url: http://localhost:1234/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001E98746CB00>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)))) ... ERROR

====================================================================== ERROR: Failure: ProxyError (HTTPConnectionPool(host='proxy.myorgname.com', port=8080): Max retries exceeded with url: http://localhost:1234/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001E98746CB00>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))))

Traceback (most recent call last): File "c:\g_venv\lib\site-packages\urllib3\connection.py", line 175, in _new_conn (self._dns_host, self.port), self.timeout, **extra_kw File "c:\g_venv\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): File "C:\python3.6\lib\socket.py", line 745, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11001] getaddrinfo failed ...`

Kabir-Khan avatar Apr 08 '22 15:04 Kabir-Khan

Going to close this, if any readers are having the same issue, please raise a new issue with reproducible steps

YOU54F avatar Aug 03 '23 11:08 YOU54F