[Python] Sync read is working while async read is not for CockroachDB using SQLAlchemy

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have CockroachDB running in my docker in secure mode.
    I have the following code, I get the output Alice for sync_read() call but below error for async_read() call.
    asyncpg.exceptions.ProtocolViolationError: node is running secure mode, SSL connection required.
    Why there is a different in behaviour between sync_read() vs async_read()?

    def sync_read():
    SYNC_DB_URL = f"cockroachdb://croachadmin:{PASSWORD}@{DBHOST}:26257/defaultdb"
    engine = create_engine(SYNC_DB_URL)
    with engine.connect() as conn:
    result = conn.execute(text("SELECT * FROM example_table"))
    print(result.first()[1])

    async def async_read():
    ASYNC_DB_URL = f"cockroachdb+asyncpg://cockroachdb:{PASSWORD}@{DBHOST}:26257/defaultdb"
    engine = create_async_engine(ASYNC_DB_URL)
    async with engine.connect() as conn:
    result = await conn.execute(text("SELECT * FROM example_table"))
    print(result.first()[1])

    if __name__ == "__main__":
    # asyncio.run(async_read())
    sync_read()

    Continue reading...

Compartilhe esta Página