0

システム: Bluez 5.38 を搭載した Ubuntu 15.10

BlueZ 4 を使用した PyBluez では、この問題は発生しませんでした。しかし、BlueZ 5 に移行し、Bluetooth コードを実行するために必要な調整を行って以来、sudo. sudoすべてを使用すると、期待どおりに機能します。ただし、sudo なしで実行すると、次のエラーがスローされます。

Traceback (most recent call last):
  File "/home/sidmeister/mymodule/py34/lib/python3.4/site-packages/PyBluez-0.22-py3.4-linux-x86_64.egg/bluetooth/bluez.py", line 240, in advertise_service
    protocols)
_bluetooth.error: (13, 'Permission denied')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/sidmeister/mymodule/mymodule/blue/receiver.py", line xxx, in some_function
    profiles=[bluetooth.SERIAL_PORT_PROFILE]
  File "/home/sidmeister/mymodule/py34/lib/python3.4/site-packages/PyBluez-0.22-py3.4-linux-x86_64.egg/bluetooth/bluez.py", line 242, in advertise_service
    raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (13, 'Permission denied')

これは、新しい bluetooth ライブラリでセキュリティが強化されたことに起因することを理解していますsudo。しかし、videoBluetooth への固有のアクセス権を持つ特別なグループ (カメラにアクセスする場合など) があり、ユーザーをそのグループのメンバーにして、Bluetooth なしでアクセスできるようになりますsudoか? 参考までに、私のユーザーはすでにdialoutグループのメンバーであり、役に立ちません。

この問題に対処できる他の方法があれば教えてください。

4

1 に答える 1

1

を使用setcapして、python 実行可能ファイルにアクセス許可を設定できます。

setcapUbuntuにインストールするには:

sudo apt-get install libcap2-bin

Python 実行可能ファイルの場所を特定するには:

which python

多くの場合、これはリンクになります。バイナリの実際のパスを把握する必要があります。私のマシンで/usr/bin/pythonは、へのリンクです/usr/bin/python2.7

実行可能ファイルに適切な権限を割り当てるには:

sudo setcap 'cap_net_raw,cap_net_admin+eip' <path-to-python-binary-here>

関連する質問: https://unix.stackexchange.com/a/182559

于 2016-04-19T03:24:17.933 に答える