Python's Bluetooth library of the Bleak report "bleak.exc.BleakError: Could not get GATT services: Unreachable" , how to solve it?

Python's Bluetooth library of the Bleak report "bleak.exc.BleakError: Could not get GATT services: Unreachable" , how to solve it?

我是菜鸟,几天无所事事只好求助溢出(┬┬﹏┬┬)

Windows10下载一个python第三方库的bleak包和conda的虚拟环境tf-gpu-3.7本地安装

使用 bleak 的示例文件:https://github.com/hbldh/bleak/blob/develop/examples/get_services.py

可以正常获取蓝牙服务特征值。我会根据文档使用read_gatt_descriptor和read_gatt_char,突然出现Pycharm的错误。 (此时我没有更改示例文件的代码)

错误:

C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\python.exe C:/Users/Administrator/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 27, in <module>
    asyncio.run(main(sys.argv[1] if len(sys.argv) == 2 else ADDRESS))
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "C:/Users/Administrator/PycharmProjects/pythonProject/main.py", line 19, in main
    async with BleakClient(address) as client:
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\client.py", line 61, in __aenter__
    await self.connect()
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 276, in connect
    await self.get_services()
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 456, in get_services
    "Could not get GATT services",
  File "C:\ProgramData\Anaconda3\envs\tf-gpu-3.7\lib\site-packages\bleak-0.15.0a1-py3.7.egg\bleak\backends\winrt\client.py", line 105, in _ensure_success
    raise BleakError(f"{fail_msg}: Unreachable")
bleak.exc.BleakError: Could not get GATT services: Unreachable

图片:https://tupian.li/images/2022/03/26/image4e67fd58c248b7b3.png

不知道怎么解决it.The错误太突然了。前段时间还好,现在不行了

我重新创建了虚拟环境,重新安装了bleak,可惜还是报错了

ESP32重启了几次,pyCharm又写了几次,都报同样的错误。前几天向作者求助,至今未回复...

ESP32代码:https://github.com/hbldh/bleak/files/8348469/BLE.UART.txt

捕获的蓝牙数据包:https://github.com/hbldh/bleak/files/8348459/ERROR.txt

如何解决突发错误:Could not get GATT services: Unreachable?

抱歉,不清楚我将在哪里描述错误...

问题结束。我找到错误的原因:

ESP.restart();

忘记评论esp.restart功能,导致ESP32一直重启。所以无法获取蓝牙的服务