首页 > 解决方案 > Python:即使检测到设备,也无法使用 PyBluez 扫描连接到蓝牙设备所需的信息

问题描述

我正在使用 PyBluez 库尝试将我的计算机连接到蓝牙扬声器。我正在运行 Windows 10。

当我使用 discover_devices 功能时,我的扬声器显示得很好:

import bluetooth as bt

devices = bt.discover_devices(10, flush_cache=True, lookup_names=True, lookup_class=True)

for d in devices:
   print d

输出:

('BB:B8:6D:D2:C1:6C', u'OontZ Angle 3 16C', 2360324) // this is my speaker

但是,当我尝试获取连接到设备所需的端口等信息时,它根本不会返回任何内容:

devices = bt.discover_devices(10, flush_cache=True, lookup_names=True, lookup_class=True)

for d in devices:
    print d
    addr = d[0]
    print bt.find_service(address=addr) // this function returns info such as port, protocol, etc about devices

输出:

('BB:B8:6D:D2:C1:6C', u'OontZ Angle 3 16C', 2360324) // this is a speaker
[] // this should be a list of information about the device

有谁知道什么会导致这种情况发生?这里有一些更多信息:

文件“C:\Python27\lib\site-packages\bluetooth\msbt.py”,第 243 行,在 find_service

结果 = bt.find_service (addr, uuidstr)

IO错误:一个

谢谢你。

标签: pythonbluetooth

解决方案


您可能需要安装另一个版本的 Python,3.5.4,然后专门为此版本的 Python 下载 Wheel 文件。

wheel 文件URL,然后使用 pip 安装它:pip install PyBluez‑0.22‑cp35‑none‑win_amd64.whl


推荐阅读