因此,当我尝试连接蓝牙时。这是我的代码:
import subprocess
import bluetooth
nearby_devices = bluetooth.discover_devices(duration=4, lookup_names=True, flush_cache=True,
lookup_class=False)
name = "HC - 06" # Device name
addr = "20:17:11:20:28:17" # Device Address
port = 1 # RFCOMM port
passkey = "1234" # passkey of the device you want to connect
# kill any "bluetooth-agent" process that is already running
subprocess.call("kill -9 `pidof bluetooth-agent`",shell=True)
# Start a new "bluetooth-agent" process where XXXX is the passkey
status = subprocess.call("bluetooth-agent " + passkey + " &",shell=True)
# Now, connect in the same way as always with PyBlueZ
try:
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
s.connect((addr,port))
except bluetooth.btcommon.BluetoothError as err:
# Error handler
pass
它有这样的错误:
Traceback (most recent call last):
File "e:/Code/number.py", line 20, in <module>
s.connect((addr,port))
File "C:\Users\huuhu\AppData\Local\Programs\Python\Python38-32\lib\site-packages\bluetooth\msbt.py", line 96, in connect
bt.connect (self._sockfd, addr, port)
OSError: A
请帮助我修复它。谢谢你!