igorbenav / SQLModel-boilerplate

An extendable async API using FastAPI, SQLModel, PostgreSQL and Redis.
MIT License
90 stars 6 forks source link

Getting "socket.gaierror: [Errno -2] Name or service not known" Error on docker compose #2

Open piyushhanchate opened 1 week ago

piyushhanchate commented 1 week ago
web-1  | ERROR:    Exception in ASGI application
web-1  | Traceback (most recent call last):
web-1  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 419, in run_asgi
web-1  |     result = await app(  # type: ignore[func-returns-value]
web-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
web-1  |     return await self.app(scope, receive, send)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
web-1  |     await super().__call__(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
web-1  |     await self.middleware_stack(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
web-1  |     raise exc
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
web-1  |     await self.app(scope, receive, _send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
web-1  |     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
web-1  |     raise exc
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
web-1  |     await app(scope, receive, sender)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 758, in __call__
web-1  |     await self.middleware_stack(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 778, in app
web-1  |     await route.handle(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 299, in handle
web-1  |     await self.app(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 79, in app
web-1  |     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
web-1  |     raise exc
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
web-1  |     await app(scope, receive, sender)
web-1  |   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
web-1  |     response = await func(request)
web-1  |                ^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 299, in app
web-1  |     raise e
web-1  |   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 294, in app
web-1  |     raw_response = await run_endpoint_function(
web-1  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
web-1  |     return await dependant.call(**values)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/code/app/api/v1/users.py", line 45, in read_users
web-1  |     users_data = await crud_users.get_multi(
web-1  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/fastcrud/crud/fast_crud.py", line 751, in get_multi
web-1  |     result = await db.execute(stmt)
web-1  |              ^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/ext/asyncio/session.py", line 461, in execute
web-1  |     result = await greenlet_spawn(
web-1  |              ^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 201, in greenlet_spawn
web-1  |     result = context.throw(*sys.exc_info())
web-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2351, in execute
web-1  |     return self._execute_internal(
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2226, in _execute_internal
web-1  |     conn = self._connection_for_bind(bind)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 2095, in _connection_for_bind
web-1  |     return trans._connection_for_bind(engine, execution_options)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "<string>", line 2, in _connection_for_bind
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/state_changes.py", line 139, in _go
web-1  |     ret_value = fn(self, *arg, **kw)
web-1  |                 ^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/orm/session.py", line 1189, in _connection_for_bind
web-1  |     conn = bind.connect()
web-1  |            ^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3276, in connect
web-1  |     return self._connection_cls(self)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 146, in __init__
web-1  |     self._dbapi_connection = engine.raw_connection()
web-1  |                              ^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 3300, in raw_connection
web-1  |     return self.pool.connect()
web-1  |            ^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 449, in connect
web-1  |     return _ConnectionFairy._checkout(self)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
web-1  |     fairy = _ConnectionRecord.checkout(pool)
web-1  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
web-1  |     rec = pool._do_get()
web-1  |           ^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/impl.py", line 179, in _do_get
web-1  |     with util.safe_reraise():
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
web-1  |     raise exc_value.with_traceback(exc_tb)
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
web-1  |     return self._create_connection()
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
web-1  |     return _ConnectionRecord(self)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 674, in __init__
web-1  |     self.__connect()
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 900, in __connect
web-1  |     with util.safe_reraise():
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
web-1  |     raise exc_value.with_traceback(exc_tb)
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
web-1  |     self.dbapi_connection = connection = pool._invoke_creator(self)
web-1  |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/create.py", line 643, in connect
web-1  |     return dialect.connect(*cargs, **cparams)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/engine/default.py", line 620, in connect
web-1  |     return self.loaded_dbapi.connect(*cargs, **cparams)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/asyncpg.py", line 932, in connect
web-1  |     await_only(creator_fn(*arg, **kw)),
web-1  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 132, in await_only
web-1  |     return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 196, in greenlet_spawn
web-1  |     value = await result
web-1  |             ^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/asyncpg/connection.py", line 2329, in connect
web-1  |     return await connect_utils._connect(
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 1017, in _connect
web-1  |     raise last_error or exceptions.TargetServerAttributeNotMatched(
web-1  |   File "/usr/local/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 991, in _connect
web-1  |     conn = await _connect_addr(
web-1  |            ^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 828, in _connect_addr
web-1  |     return await __connect_addr(params, True, *args)
web-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 873, in __connect_addr
web-1  |     tr, pr = await connector
web-1  |              ^^^^^^^^^^^^^^^
web-1  |   File "/usr/local/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 744, in _create_ssl_connection
web-1  |     tr, pr = await loop.create_connection(
web-1  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1  |   File "uvloop/loop.pyx", line 1978, in create_connection
web-1  | socket.gaierror: [Errno -2] Name or service not known

I'm getting this error when trying to run using docker compose up

piyushhanchate commented 1 week ago

Solved it! Turns out you can't use '@' in POSTGRES_PASSWORD. It's what causes this error.

Refer this:[(https://github.com/MagicStack/asyncpg/issues/471)]

igorbenav commented 1 day ago

Solved it! Turns out you can't use '@' in POSTGRES_PASSWORD. It's what causes this error.

Refer this:[(https://github.com/[MagicStack/asyncpg/issues/471](https://github.com/MagicStack/asyncpg/issues/471))]

Nice one! I'll add it to the docs