这是我的代码,我收到错误消息:
Ausnahme: BluetoothError
[Errno 104] Connection reset by peer
File "<string>", line 3, in sendall
_bluetooth.error: (104, 'Connection reset by peer')
During handling of the above exception, another exception occurred:
File "/home/eggplant/Dokumente/test.py", line 25, in <module>
sock.sendall(block)
bluetooth.btcommon.BluetoothError: [Errno 104] Connection reset by peer
执行代码时:
from bluetooth import *
server_mac = '34:29:12:5E:09:10'#20:F4:78:56:EF:7D'
port = 3 # Port für OBEX Object Push Profile
sock = BluetoothSocket(RFCOMM)
try:
sock.connect((server_mac, port))
print("Verbunden mit", server_mac)
except BluetoothError as e:
print("Bluetooth Fehler beim Verbinden:", e)
sock.close()
exit(1)
file_path = 'hallo_welt_mp3.wav'
block_size = 1024 # Größe des Datenblocks zum Senden
with open(file_path, "rb") as f:
while True:
block = f.read(block_size)
if not block:
break # Ende der Datei erreicht
try:
sock.sendall(block)
except BluetoothError as e:
print("Bluetooth Fehler beim Senden:", e)
break
print("Datei erfolgreich gesendet.")
sock.close()
有人发现错误或可以帮助我吗?我真的很感激一些帮助。提前致谢!
错误
"connection reset by peer"
通常在远程设备(在本例中为智能手机)意外关闭连接时发生。导致此错误的原因有多种,例如超时、蓝牙配置文件不兼容或蓝牙连接本身存在问题。你可以尝试:
library
或 module
。有可用的替代库,例如 PyBluez
或 Bluez
,它们可能提供更好的兼容性。