Psycopg3 无法异步连接
无法使用异步 psycopg3 连接 postgres 数据库:
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 上
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是工作解决方案
Here is the working solution