from pydantic import BaseModel, FilePath, StrictStr, PositiveInt
from pydantic_settings import BaseSettings, SettingsConfigDict
class APISettings(BaseModel):
prefix: StrictStr
class PostgresSettings(BaseModel):
url: StrictStr
class AuthJWTSettings(BaseModel):
private_key_path: FilePath
public_key_path: FilePath
algorithm: StrictStr
access_token_expire_minutes: PositiveInt
class RedisSettings(BaseModel):
url: StrictStr
ttl: PositiveInt
class Settings(BaseSettings):
api: APISettings
postgres: PostgresSettings
auth: AuthJWTSettings
redis: RedisSettings
model_config = SettingsConfigDict(
env_nested_delimiter='__',
env_file='.env',
env_file_encoding='utf-8',
extra='ignore',
)
settings = Settings()
async def create_pool():
return await asyncpg.create_pool(user=user, password=password, database=database,
host=host, port=port, command_timeout=60)
USER = test_bot
PASSWORD = 12345lala
DATABASE = test_user_data
HOST = localhost
PORT = 5432
async def create_pool():
return await asyncpg.create_pool(user=user, password=password, database=database,
host=host, port=port, command_timeout=60)
USER = test_bot
PASSWORD = 12345lala
DATABASE = test_user_data
HOST = localhost
PORT = 5432
root@TestBot:~/test-bot/src# python3 main.py
Traceback (most recent call last):
File "/root/test-bot/src/main.py", line 42, in <module>
asyncio.run(main())
File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/root/test-bot/src/main.py", line 27, in main
pool_connect = await create_pool()
^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/src/main.py", line 17, in create_pool
return await asyncpg.create_pool(user=user, password=password, database=database,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/pool.py", line 403, in _async__init__
await self._initialize()
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/pool.py", line 430, in _initialize
await first_ch.connect()
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/pool.py", line 128, in connect
self._con = await self._pool._get_new_connection()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/pool.py", line 502, in _get_new_connection
con = await connection.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/connection.py", line 2329, in connect
return await connect_utils._connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 991, in _connect
conn = await _connect_addr(
^^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 833, in _connect_addr
return await __connect_addr(params_retry, False, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/test-bot/venv/lib/python3.11/site-packages/asyncpg/connect_utils.py", line 876, in __connect_addr
await connected
asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "root"