OSError: [WinError 10051] A socket operation was attempted to an unreachable network

675 views Asked by At

I tried to connect my headphone with using Bluetooth. I used the pybluez2 module, and I got this error:

OSError: [WinError 10051] A socket operation was attempted to an unreachable network

Here is my connect_to_device function:

if target_address is not None:
    print("Device found: ", target_address)
    port = 1
    sock = bluetooth.BluetoothSocket(bluetooth.Protocols.RFCOMM)
    sock.connect((target_address, port)) # This line is causing the error
    print("Device connected.")
    return True

I tried to change the port number, but it didn't seem relevant. And I also tried this:

sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)

But then I got a KeyError.

0

There are 0 answers