question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

scanner.start() results in `_bluetooth.error: (1, 'Operation not permitted')`

See original GitHub issue

First: I know this is a permissions issue - and I also see the step in the setup instructions to mitigate it.

System:

Ubuntu 17.10 x64 Pycharm 2018.1.3 (developing here) Python 3.6 in a virtualenv

Steps to Replicate:

pip install beacontools
# install libbluetooth headers and libpcap2
sudo apt-get install python-dev libbluetooth-dev libcap2-bin
# grant the python executable permission to access raw socket data
sudo setcap 'cap_net_raw,cap_net_admin+eip' $(readlink -f $(which python))
# install beacontools with scanning support
pip install beacontools[scan]

Then copy-paste example code from Scanner subsection (scanner = BeaconScanner...)

Traceback

Exception in thread Thread-5:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/william/PycharmProjects/bt-beacon/venv/lib/python3.6/site-packages/beacontools/scanner.py", line 94, in run
    self.toggle_scan(True)
  File "/home/william/PycharmProjects/bt-beacon/venv/lib/python3.6/site-packages/beacontools/scanner.py", line 110, in toggle_scan
    self.bluez.hci_send_cmd(self.socket, OGF_LE_CTL, OCF_LE_SET_SCAN_ENABLE, command)
_bluetooth.error: (1, 'Operation not permitted')

Things I Tried

Various forms of sudo setcap... including sudo setcap 'cap_net_raw,cap_net_admin+eip' $(which hcitool)'.

Has anyone else experienced and solved this issue?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
citruzcommented, May 23, 2018

Try executing sudo setcap 'cap_net_raw,cap_net_admin+eip' $(readlink -f $(which python))inside your venv.

0reactions
williamflyntcommented, May 28, 2018

Problem solved. From the above StackOverflow post by Graham King:

This might be because your home directory is mounted with nosuid, which seems to prevent capabilities working. Ubuntu encrypts the home directory, and mounts that with ecryptfs as nosuid.

This is critical, because capabilities (ie: setcap) is what allows this script to function without using sudo python. I cloned the project into my /tmp directory and there are no issues with running the scan.

I hope this helps others!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bluetooth LE scan as non root?
The "Operation not permitted" error is generated by a writev system call, with the call stack locking as follows (all functions implemented ...
Read more >
bleerror: cannot start scanning operation
I'm getting the following error when I'm trying to call this.manager.startDeviceScan method. I did the following but non of them solved the issue....
Read more >
IOBluetooth | Apple Developer Forums
Hi Apple developer experts, I am getting one critical issue related to Bluetooth on MacOS 12.0.1 and MacOS 12.1. Since we upgrade to...
Read more >
raspberry pi - hcitool lescan shows I/O error
What worked for me though is opening up the Bluetooth settings on my Ubuntu and manually removing the unused devices. Immediately ...
Read more >
ScanCallback
Fails to start power optimized scan as this feature is not supported. int, SCAN_FAILED_INTERNAL_ERROR. Fails to start scan due an internal error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found