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

httpx.ConnectError: [Errno 111] Connection refused #937

Open
cgtopher opened this issue Apr 4, 2024 · 3 comments
Open

httpx.ConnectError: [Errno 111] Connection refused #937

cgtopher opened this issue Apr 4, 2024 · 3 comments

Comments

@cgtopher
Copy link

cgtopher commented Apr 4, 2024

Bug description

Getting "Connection Refused" error on connect to db. I've tested the networking with psql to verify my connection isn't getting blocked by firewalls, using same connection details.

How to reproduce

Not sure how reproducible this can be, but this is the minimal code I've been using to test it (normally running inside a flask application running behind gunicorn).

(venv) <user>@ubuntu-s-2vcpu-4gb-amd-sfo3-01:/<home-dir># export PRISMA_PY_DEBUG=1 && python
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from prisma import Prisma
>>> import logging
>>> p = Prisma()
>>> logging.getLogger('prisma').setLevel(logging.DEBUG)
>>> p.connect()

I'll put resulting logs in comments.

Expected behavior

Connects to database

Prisma information

generator client {
  provider             = "prisma-client-py"
  interface            = "sync"
  recursive_type_depth = 5
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Environment & setup

  • OS: Ubuntu 23.10
  • Database: PostgreSQL
  • Python version: 3.11.6
  • Prisma version:
prisma                  : 5.11.0
prisma client python    : 0.13.0
platform                : debian-openssl-3.0.x
expected engine version : efd2449663b3d73d637ea1fd226bafbcf45b3102
installed extras        : []
install path            : /<home-dir>/venv/lib/python3.11/site-packages/prisma
binary cache dir        : /<user>/.cache/prisma-python/binaries/5.11.0/efd2449663b3d73d637ea1fd226bafbcf45b3102
@cgtopher
Copy link
Author

cgtopher commented Apr 4, 2024

Logs from running .connect()

{"timestamp":"2024-04-03T23:49:14.423644Z","level":"INFO","fields":{"message":"Starting a postgresql pool with 5 connections."},"target":"quaint::pooled"}
{"timestamp":"2024-04-03T23:49:14.494218Z","level":"INFO","fields":{"message":"Started query engine http server on http://127.0.0.1:37103","ip":"127.0.0.1","port":"37103"},"target":"query_engine::server"}
Traceback (most recent call last):
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
    yield
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 206, in connect_tcp
    sock = socket.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/socket.py", line 851, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.11/socket.py", line 836, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 67, in map_httpcore_exceptions
    yield
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 231, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 268, in handle_request
    raise exc
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 251, in handle_request
    response = connection.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 99, in handle_request
    raise exc
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 76, in handle_request
    stream = self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 124, in _connect
    stream = self._network_backend.connect_tcp(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 205, in connect_tcp
    with map_exceptions(exc_map):
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.ConnectError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/<home-dir>/venv/lib/python3.11/site-packages/prisma/engine/_query.py", line 208, in spawn
    data = self.request('GET', '/status')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/prisma/engine/_http.py", line 150, in request
    response = self.session.request(method, url, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/prisma/_sync_http.py", line 25, in request
    return Response(self.session.request(method, url, **kwargs))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_client.py", line 828, in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_client.py", line 915, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_client.py", line 943, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_client.py", line 980, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_client.py", line 1016, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 230, in handle_request
    with map_httpcore_exceptions():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/<home-dir>/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 84, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectError: [Errno 111] Connection refused

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/<home-dir>/venv/lib/python3.11/site-packages/prisma/_base_client.py", line 305, in connect
    self._internal_engine.connect(
  File "/<home-dir>/venv/lib/python3.11/site-packages/prisma/engine/_query.py", line 190, in connect
    self.spawn(file, timeout=timeout, datasources=datasources)
  File "/<home-dir>/venv/lib/python3.11/site-packages/prisma/engine/_query.py", line 229, in spawn
    raise errors.EngineConnectionError('Could not connect to the query engine') from last_exc
prisma.engine.errors.EngineConnectionError: Could not connect to the query engine

@vikyw89
Copy link

vikyw89 commented May 1, 2024

same here

@egcash
Copy link

egcash commented May 9, 2024

Exactly same issue

Bug description

Getting "Connection Refused" error on connect to db. I've tested the networking with psql to verify my connection isn't getting blocked by firewalls, using same connection details.

How to reproduce

Not sure how reproducible this can be, but this is the minimal code I've been using to test it (normally running inside a flask application running behind gunicorn).

(venv) <user>@ubuntu-s-2vcpu-4gb-amd-sfo3-01:/<home-dir># export PRISMA_PY_DEBUG=1 && python
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from prisma import Prisma
>>> import logging
>>> p = Prisma()
>>> logging.getLogger('prisma').setLevel(logging.DEBUG)
>>> p.connect()

I'll put resulting logs in comments.

Expected behavior

Connects to database

Prisma information

generator client {
  provider             = "prisma-client-py"
  interface            = "sync"
  recursive_type_depth = 5
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Environment & setup

  • OS: Ubuntu 23.10
  • Database: PostgreSQL
  • Python version: 3.11.6
  • Prisma version:
prisma                  : 5.11.0
prisma client python    : 0.13.0
platform                : debian-openssl-3.0.x
expected engine version : efd2449663b3d73d637ea1fd226bafbcf45b3102
installed extras        : []
install path            : /<home-dir>/venv/lib/python3.11/site-packages/prisma
binary cache dir        : /<user>/.cache/prisma-python/binaries/5.11.0/efd2449663b3d73d637ea1fd226bafbcf45b3102

Exactly same issue

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

3 participants