使用PyBluez和PyOBEX通过蓝牙发送文件

2024-04-26 00:25:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过蓝牙将一个文件从我的笔记本电脑(win10)发送到我的手机(android)。我遵循了this answer,我正在用python 3.6做同样的事情

我正在使用PyOBEX Python 3 Package,这就是我尝试过的

import sys
from PyOBEX.client import Client
from bluetooth import *

addr = '60:7E:DD:A7:42:43' 


print("Searching for OBEX service on {}".format(addr))
services = find_service(address=addr, name=b'OBEX Object Push\x00')
if len(services) == 0:
    sys.exit()


first_match = services[0]
port = first_match["port"]

client = Client(addr, port)
client.connect()
client.put("test.txt", "Hello world\n")
client.disconnect()

当我运行此操作时,会发现设备,但它不会建立连接或发送文件。这就是它给出的错误

enter image description here

我试图通过将socket.recv返回的数据类型更改为str来搞乱PyOBEX包,但它给了我另一个错误, enter image description here

我被卡住了,以前从未使用过蓝牙或插座。谢谢你的帮助


Tags: 文件fromimportclientportmatch错误service