在Ubuntu中创建套接字的Python权限错误

时间:2018-12-15 16:13:56

标签: python linux ubuntu socketcan

我正在使用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身份运行脚本。这似乎很有风险。

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

0 个答案:

没有答案