[Python] Psycopg3 unable to connect async

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

  1. Stack

    Stack Membro Participativo

    Unable to connect postgres database using async psycopg3 :

    import asyncio
    import psycopg

    async def main():
    async with await psycopg.AsyncConnection.connect('postgresql://xxxxxxxxxxx') as con:
    async with con.cursor() as cur:
    print(await cur.execute('select 1 a').fetchall())

    if __name__ == '__main__':
    asyncio.run(main())


    I get error:

    psycopg.InterfaceError: Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'


    On Windows 10, Python 3.9, Psycopg 3.0.8

    Continue reading...

Compartilhe esta Página