Original GitHub Issue


  • Operating System: MacOS 10.14.6
  • Hardware: N/A
  • Python Version: Python 3.7.4
  • PyBluez Version: Installed 8/14/2019 via python3 -m pip install git+https://github.com/pybluez/pybluez.git
    • Installation of LightAquaBlue:
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
$ sudo python3 setup.py install

# Line below to address the following error:
# ImportError: Cannot load LightAquaBlue framework, not found at /usr/local/lib/python3.7/site-packages/lightblue/LightAquaBlue.framework
$ ln -s /Library/Frameworks/LightAquaBlue.framework /usr/local/lib/python3.7/site-packages/lightblue/LightAquaBlue.framework


Running the following

import bluetooth
port = 0 # must be zero for MacOS

results the following error:

Traceback (most recent call last):
  File "bluetooth_tests.py", line 4, in <module>
  File "/usr/local/lib/python3.7/site-packages/bluetooth/macos.py", line 110, in bind
    return self._sock.bind(addrport)
  File "/usr/local/lib/python3.7/site-packages/lightblue/_bluetoothsockets.py", line 273, in bind
    address = (address[0], _getavailableport(self.__conn.proto))
  File "/usr/local/lib/python3.7/site-packages/lightblue/_bluetoothsockets.py", line 69, in _getavailableport
    "Could not retrieve an available service channel")
lightblue._lightbluecommon.BluetoothError: [Errno -536870208] Could not retrieve an available service channel

which is caused by this line

result = BBServiceAdvertiser.removeService_(servicerecordhandle)

returning -536870208 instead of _macutil.kIOReturnSuccess, which takes a value of 0.

Looking into ObjectiveC backend, BBServiceAdvertiser._removeService calls IOBluetoothRemoveServiceWithRecordHandle. (I don't know much about ObjectiveC or Mac system programing, but this implies it will be removed soon).

+ (IOReturn)removeService:(BluetoothSDPServiceRecordHandle)handle
    // TODO: We should switch to using [IOBluetoothSDPServiceRecord removeServiceRecord]
    // but we don't know how to get an IOBluetoothSDPServiceRecord instance from a handle.
    return IOBluetoothRemoveServiceWithRecordHandle(handle);

I don't have the background to say what the cause of this is, but I would greatly appreciate any help.

New contributor
Phoenix Meadowlark is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Phoenix Meadowlark is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.