scanner.start() results in `_bluetooth.error: (1, 'Operation not permitted')`
See original GitHub issueFirst: 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:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try executing
sudo setcap 'cap_net_raw,cap_net_admin+eip' $(readlink -f $(which python))
inside your venv.Problem solved. From the above StackOverflow post by Graham King:
This is critical, because capabilities (ie:
setcap
) is what allows this script to function without usingsudo python
. I cloned the project into my/tmp
directory and there are no issues with running the scan.I hope this helps others!