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

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

Open
piyushhanchate opened this issue Jun 27, 2024 · 4 comments

Comments

@piyushhanchate
Copy link

piyushhanchate commented Jun 27, 2024

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
Copy link
Author

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
Copy link
Owner

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)]

Nice one! I'll add it to the docs

@Mte90
Copy link
Contributor

Mte90 commented Oct 30, 2024

I have the same issue but with poetry but in my case I didn't configured postgres.
I was trying to see if I can use locally sqlite for development.

@igorbenav
Copy link
Owner

Hey, @Mte90, can you please send me a minimal example to replicate it?

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