PermissionError

Hi,

We are trying to use Python socket library but get an error on permission
  
[i]File "/opt/plcnext/test/pnio_dcp/pnio_dcp.py", line 66, in __init__
    self.__socket = L2Socket(ip=ip, interface=network_interface, filter=socket_filter,
  File "/opt/plcnext/test/pnio_dcp/l2socket/l2socket.py", line 69, in __init__
    self.socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(protocol))
  File "/usr/lib/python3.8/socket.py", line 231, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted[/i]

Is there a way to get this permission?

Best regards Stefan

I googled this problem and some suggestions included:
- run python as root user
- change the capability of the python program, using a command something like:

[code]setcap cap_net_raw+ep $(readlink -f $(which python3))[/code]
(executed as root)

If I run as root it works fine. The problem is that I want to run it from PLC with the plcnextbase PBCL_SysLinuxShell_1. Is it possible to do run command as root from PLC?

No, I’m fairly sure that it’s not possible to execute commands as root using the PBCL_SysLinuxShell_1 function block. But the developers of the PLCnextBase library can confirm that, if you want to contact them through the PLCnext Store.

Otherwise, does changing the capability of the python executable help?

I tried that and it works fine.
Thanks for quick response.

Br Stefan