Psycopg3 не может подключиться асинхронноPython

Программы на Python
Anonymous
Psycopg3 не может подключиться асинхронно

Сообщение Anonymous »

Невозможно подключить базу данных Postgres с помощью 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())
Я получаю сообщение об ошибке:

Код: Выделить всё

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())'
В Windows 10, Python 3.9, Psycopg 3.0.8

Подробнее здесь: https://stackoverflow.com/questions/712 ... nect-async

Вернуться в «Python»