python runtime_error ai_generated true

NotImplementedError: 此事件循环不支持数据报端点

NotImplementedError: Datagram endpoints are not supported on this event loop

ID: python/asyncio-datagram-endpoint-not-supported

其他格式: JSON · Markdown 中文 · English
80%修复率
84%置信度
0证据数
2024-10-22首次发现

版本兼容性

版本状态引入弃用备注
3.8+ active
3.9+ active
3.10+ active
3.11+ active
3.12+ active

根因分析

在 ProactorEventLoop(Windows 默认)上调用了 create_datagram_endpoint(),它不支持 UDP 数据报。

English

create_datagram_endpoint() was called on a ProactorEventLoop (Windows default), which does not support UDP datagrams.

generic

解决方案

  1. 95% 成功率
    import asyncio, sys
    if sys.platform == 'win32':
        asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    asyncio.run(main())
  2. 90% 成功率
    import uvloop
    uvloop.install()
    asyncio.run(main())

无效尝试

常见但无效的做法:

  1. 95% 失败

    The loop type does not change; retry raises the same error.

  2. 70% 失败

    Loses async semantics and does not integrate with the loop's datagram protocol.