PermissionError: [Errno 1] Operation not permitted

24,729

This means that you need to start your script with sudo/admin rights.

Share:
24,729
Kashif Ahmad
Author by

Kashif Ahmad

Updated on June 02, 2020

Comments

  • Kashif Ahmad
    Kashif Ahmad over 2 years

    I am completely new to python, linux RPI and scapy. I am trying to send some packets using scapy.
    On Command Line (only if super user privileges are given to scapy)

    send(IP(dst="1.2.3.4")/ICMP())
    

    This works perfectly, while running on python script.

    from scapy.all import *
    p=send(IP(dst="1.2.3.4")/ICMP())
    

    Throws an error

    Traceback (most recent call last):
      File "<pyshell#19>", line 1, in <module>
        send(IP(dst="1.2.3.4")/ICMP())
      File "/usr/local/lib/python3.4/dist-packages/scapy/sendrecv.py",line   255, in send
        __gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
      File "/usr/local/lib/python3.4/dist-packages/scapy/arch/linux.py", line 326, in __init__
        self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
      File "/usr/lib/python3.4/socket.py", line 123, in __init__
        _socket.socket.__init__(self, family, type, proto, fileno)
    PermissionError: [Errno 1] Operation not permitted<br>
    

    I am trying to solve it but cannot, I am new to the environment therefore don't know much. As far as my search goes this issue is relevant to sockets. But I still need some simple explanation to understand.

  • Kashif Ahmad
    Kashif Ahmad over 5 years
    I am aware with this but how to give admin rights within the script that it works fine inside shell?
  • Cukic0d
    Cukic0d over 5 years
    It depends of your OS: if you are on *nix, use sudo python script.py on windows, you can start a cmd as admin (explorer) then start your file
  • Kashif Ahmad
    Kashif Ahmad over 5 years
    I don't want to start my file on CLI (by the way its Linux) but I want to run my script directly via shell. If I try to run it using 'sudo' in command line it works fine but whenever I try to run it directly within python shell I cannot do it. I actually do not know, how to give admin or sudo rights within the python script.
  • Cukic0d
    Cukic0d over 5 years
    Because you need to start the python shell with sudo: sudo python