A
A
Andrey Ivanov2021-09-19 18:43:47
Python
Andrey Ivanov, 2021-09-19 18:43:47

Why can't I connect to user PostgreSQL?

I'm trying to create a Telegram bot using the aiogram library. It came down to creating a database. Initially I wanted to use SQLite, but I found information that it is better to use PostgreSQL, since it has asynchronous connectors and one of the best libraries for this at the moment is asyncpg. I installed PostgreSQL and PgAdmin4 on my PC (Windows 10). Created Usera and base for it as specified here .

However, when connecting to the database by code:

class PgDatabase:

    def __init__(self, loop: asyncio.AbstractEventLoop):
        self.pool: asyncpg.pool.Pool = loop.run_until_complete(
            asyncpg.create_pool(
                user=PgUser,
                password=PgPassword,
                host="localhost"
            )
        )
test_connect = PgDatabase(loop=asyncio.get_event_loop())

I keep getting asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "TestUser".

When you log in to PgAdmin, this user exists, the password for it is correct. What can cause the error and how can it be fixed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-09-19
@TomRiddle

Perhaps pgadmin goes through a socket or localhost, and the bot goes to a normal IP address, while there is no corresponding rule in pg_hba?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question