python - 尝试使用 python 库连接到 coap 资源

标签 python python-asyncio coap

所以我尝试使用这个 python 库连接到 CoaP 资源 https://github.com/chrysn/aiocoap 。该库使用 python 3.4,我安装了 3.4 并将其设置为与此一起使用的解释器(顺便说一句,我在 Windows 7 上)。在执行 clientGET.py 文件时,我仍然收到此错误消息。服务器文件也是如此。

C:\Python34\python.exe C:/Learning/PyCoap/aiocoap/clientGET.py
Traceback (most recent call last):
  File "C:/Learning/PyCoap/aiocoap/clientGET.py", line 34, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "C:\Python34\lib\asyncio\base_events.py", line 268, in run_until_complete
    return future.result()
  File "C:\Python34\lib\asyncio\futures.py", line 277, in result
    raise self._exception
  File "C:\Python34\lib\asyncio\tasks.py", line 236, in _step
    result = next(coro)
  File "C:/Learning/PyCoap/aiocoap/clientGET.py", line 20, in main
    protocol = yield from Context.create_client_context()
  File "C:\Learning\PyCoap\aiocoap\aiocoap\protocol.py", line 510, in create_client_context
    transport, protocol = yield from loop.create_datagram_endpoint(protofact, family=socket.AF_INET6)
  File "C:\Python34\lib\asyncio\base_events.py", line 675, in create_datagram_endpoint
    waiter)
  File "C:\Python34\lib\asyncio\selector_events.py", line 68, in _make_datagram_transport
    address, waiter, extra)
  File "C:\Python34\lib\asyncio\selector_events.py", line 911, in __init__
    super().__init__(loop, sock, protocol, extra)
  File "C:\Python34\lib\asyncio\selector_events.py", line 452, in __init__
    self._extra['sockname'] = sock.getsockname()
OSError: [WinError 10022] Ein ungultiges Argument wurde angegeben

Process finished with exit code 1

最佳答案

我没有在真正的 Python 中探索这个问题,因为我没有方便使用 Python 3.4 的 Windows 机器,但在我看来,这可能是 asyncio 中的一个错误。它的 UDP 套接字创建可能根本无法在 Windows 上工作。在较低级别上做一些实验,看看 aiocoap 正在做什么,并尝试证明我是错的。

它应该可以工作,documentation仅提到 ProactorEventLoop 不支持 UDP。

错误情况在Socket.error: Invalid Argument supplied中描述。 。

aiocoap.protocol.Context.create_client_context() 根据asyncio文档似乎做了正确的事情,但是_SelectorTransport.__init__() 将始终在发送任何数据包之前调用 sock.getsockname(),此时套接字将不会绑定(bind)到地址(根据链接的 SO 问题)和 getsockname() 在 Windows 上会失败。

关于python - 尝试使用 python 库连接到 coap 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31371055/

相关文章:

python - 如何衡量 Python 的 asyncio 代码性能?

java - 如何设置 Coap Observer 来监听响应

python - ArrayFire 和 Python

python - 如果值为 true 但为 null 则不起作用

python - 安装 Python 请求

java - CoAP 服务器无法启动

node.js - node.js 中的 OneM2M coap 客户端

python - 返回变量并分配属性

azure - 使用 Asyncio(异步)接收消息并获取变量作为最终结果

python - asyncio.TimeoutError 永远不会引发