python runtime_error ai_generated true

NotImplementedError: Datagram endpoints are not supported on this event loop

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

Also available as: JSON · Markdown · 中文
80%Fix Rate
84%Confidence
0Evidence
2024-10-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.8+ active
3.9+ active
3.10+ active
3.11+ active
3.12+ active

Root Cause

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

generic

中文

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

Workarounds

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

Dead Ends

Common approaches that don't work:

  1. 95% fail

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

  2. 70% fail

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