python - 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
有谁知道什么会导致这种情况发生?这里有一些更多信息:
- 如果我只是做一个通用的 bt.find_service() 而不指定mac地址,同样的事情会发生
- 根据我看到的另一篇文章,我正在运行 pybluez-win10 而不是默认的 pybluez。在 pybluez 的基础版本上运行时,上面的代码给出了以下错误和堆栈跟踪:
文件“C:\Python27\lib\site-packages\bluetooth\msbt.py”,第 243 行,在 find_service
结果 = bt.find_service (addr, uuidstr)
IO错误:一个
- 这个错误从未出现在 pybluez-win10 中,而是函数的输出,如前所述,是空的。
谢谢你。
解决方案
您可能需要安装另一个版本的 Python,3.5.4,然后专门为此版本的 Python 下载 Wheel 文件。
wheel 文件URL,然后使用 pip 安装它:pip install PyBluez‑0.22‑cp35‑none‑win_amd64.whl
推荐阅读
- sql - 使用 distinct 和 row_number 分页时的性能
- spring-restdocs - 如何使 Spring Rest Docs 看起来像 Swagger?
- android - ionic 4: android 权限在 prod 构建后不起作用
- postgresql - 匹配邮政编码和城市名称 - 在 PostgreSQL 中非常慢
- xbox - 如何向 Xbox Live Restful API 发送请求?
- arrays - 如何使用 ng-repeat 访问动态数组并获取键值对
- javascript - 为长度创建一个 .row.cells 行
- apache-pig - 通过对连接结果进行说明,我得到了完美的结果,但转储不能正常工作
- tensorflow - 使用 CNN 进行图像回归
- javascript - React:如何在“页面”之间传递数据并处理页面重新加载?