Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当I';我正在尝试连接蓝牙。我怎样才能修好它?(连接板蓝牙HC-06)_Python_Python 3.x_Bluetooth_Python Requests - Fatal编程技术网

Python 当I';我正在尝试连接蓝牙。我怎样才能修好它?(连接板蓝牙HC-06)

Python 当I';我正在尝试连接蓝牙。我怎样才能修好它?(连接板蓝牙HC-06),python,python-3.x,bluetooth,python-requests,Python,Python 3.x,Bluetooth,Python Requests,所以当我尝试连接蓝牙时。这是我的代码: 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&quo

所以当我尝试连接蓝牙时。这是我的代码:

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
回溯(最近一次呼叫最后一次):
文件“e:/Code/number.py”,第20行,在
s、 连接((地址,端口))
文件“C:\Users\huuhu\AppData\Local\Programs\Python\Python38-32\lib\site packages\bluetooth\msbt.py”,第96行,在connect中
bt.connect(自连接、地址、端口)
错误:A

请帮我修一下。谢谢你

这是我试图连接蓝牙板“HC-06”的代码,请您的问题添加一些解释,而不是像您那样使用注释。
kill-9
bluetooth agent
看起来像Linux系统上的命令,在错误消息中有
C:\Users\huuhu\AppData\Local\Programs\Python\Python38-32\lib\site packages\bluetooth
,看起来像是在Windows系统上。你在哪种类型的系统上运行它?这是一个代码,我正在尝试连接蓝牙板“HC-06”,请你的问题添加一些解释,而不是像你那样使用注释。
kill-9
bluetooth agent
看起来像Linux系统上的命令,在错误消息中有
C:\Users\huuhu\AppData\Local\Programs\Python\Python38-32\lib\site packages\bluetooth
,看起来像是在Windows系统上。您正在运行哪种类型的系统?