2

我正在使用socketCAN连接到 Ubuntu 16.04 中的 CAN 总线。该界面在我的机器上运行良好。但是,当我启动 CI 时,它会在远程代理(也是 Ubuntu 16.04)上执行,并且在尝试创建套接字时收到权限错误:

Traceback (most recent call last):
  File "main.py", line 20, in <module>
    from    tests_smoke             import SmokeTests
  File ".../tests_smoke.py", line 9, in <module>
    from tests.validate_can                 import ValidateCAN
  File ".../tests/validate_can.py", line 16, in <module>
    bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=250000)
  File "/usr/local/lib/python3.5/dist-packages/can/interface.py", line 128, in __new__
    return cls(channel, *args, **config)
  File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 459, in __init__
    self.socket = create_socket()
  File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 330, in create_socket
    sock = socket.socket(PF_CAN, socket.SOCK_RAW, CAN_RAW)
  File "/usr/lib/python3.5/socket.py", line 134, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted

作为 Linux 和 Python 的新手,我不确定如何解决这个问题。我在几个地方读到这可能是从调用进程继承的文件创建权限问题,所以我在脚本的开头放置了一个“os.umask(0)”并且没有任何影响。

我还读到可能需要以 root 身份运行脚本。这似乎相当冒险。

解决此问题的最佳方法是什么?

4

0 回答 0