This question already has an answer here:
ICMP pinger application in Python - error: operation not permitted?
(1 answer)
Closed 2 months ago.
By running this simple code in Python
>>> from pythonping import ping
>>> ping('127.0.0.1', verbose=True)
I get this error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/j0tz/.local/lib/python3.10/site-packages/pythonping/__init__.py", line 81, in ping
comm = executor.Communicator(target, provider, timeout, interval, socket_options=options, verbose=verbose, output=out,
File "/home/j0tz/.local/lib/python3.10/site-packages/pythonping/executor.py", line 293, in __init__
self.socket = network.Socket(target, 'icmp', options=socket_options, source=source)
File "/home/j0tz/.local/lib/python3.10/site-packages/pythonping/network.py", line 31, in __init__
self.socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, self.protocol)
File "/usr/lib/python3.10/socket.py", line 232, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
I tried running it as sudo but to no avail.
I don't know what the cause of the error is, so I'm hoping for intelligent answers from knowledgeable people.
Pythonping is a public repository I found on PyPI.
In the code I try to simply ping Localhost, returning the results on the screen when I set the "verbose" parameter to True.
you need root user permission to use it
run python3 such as root user then everything will be OK. and if you use it on a file run it with the root user.
Related
I am using socketCAN to interface to a CAN bus in Ubuntu 16.04. The interface works fine on my machine. However, when I kick off our CI, it executes on a remote agent (also Ubuntu 16.04) and I am receiving a permission error when the socket is creation is attempted:
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
Being a novice in both Linux and Python, I'm not positive how to address this. I read in a few places that this may be a file creation permission issue which is inherited from the calling process so I have placed a "os.umask(0)" at the beginning of the script and that had no impact.
I've also read that it may be necessary to run the script as root. This seems quite risky.
What is the best way to fix this?
So im trying to connect to a CoaP Resource using this python library https://github.com/chrysn/aiocoap . The library uses python 3.4 and i have 3.4 installed and set as the interpreter to use with this (Im on Windows 7 btw). Still im getting this error message, when executing the clientGET.py file. Same for the server file.
C:\Python34\python.exe C:/Learning/PyCoap/aiocoap/clientGET.py
Traceback (most recent call last):
File "C:/Learning/PyCoap/aiocoap/clientGET.py", line 34, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "C:\Python34\lib\asyncio\base_events.py", line 268, in run_until_complete
return future.result()
File "C:\Python34\lib\asyncio\futures.py", line 277, in result
raise self._exception
File "C:\Python34\lib\asyncio\tasks.py", line 236, in _step
result = next(coro)
File "C:/Learning/PyCoap/aiocoap/clientGET.py", line 20, in main
protocol = yield from Context.create_client_context()
File "C:\Learning\PyCoap\aiocoap\aiocoap\protocol.py", line 510, in create_client_context
transport, protocol = yield from loop.create_datagram_endpoint(protofact, family=socket.AF_INET6)
File "C:\Python34\lib\asyncio\base_events.py", line 675, in create_datagram_endpoint
waiter)
File "C:\Python34\lib\asyncio\selector_events.py", line 68, in _make_datagram_transport
address, waiter, extra)
File "C:\Python34\lib\asyncio\selector_events.py", line 911, in __init__
super().__init__(loop, sock, protocol, extra)
File "C:\Python34\lib\asyncio\selector_events.py", line 452, in __init__
self._extra['sockname'] = sock.getsockname()
OSError: [WinError 10022] Ein ungultiges Argument wurde angegeben
Process finished with exit code 1
I didn't explore this in a real Python, as I don't have a Windows machine with Python 3.4 handy, but it seems to me that this could be a bug in asyncio. Its UDP socket creation probably simply doesn't work on Windows. Do some experimenting on the lower level, looking at what aiocoap is doing, and try to prove me wrong.
It's supposed to work, documentation only mentions ProactorEventLoop as not supporting UDP.
The error condition is described in Socket.error: Invalid Argument supplied .
aiocoap.protocol.Context.create_client_context() seems to be doing the right thing according to asyncio documentation, but _SelectorTransport.__init__() will always call sock.getsockname() before any packets are sent, at which point the socket will not be bound to an address (according to the linked SO question) and getsockname() will fail on Windows.
You might want to retry with a current version of Python and aiocoap (current development version, after 0.4a1). Windows used not to be supported in aiocoap, and is still not supporting all of CoAP, but now uses a socket implementation that is aware of some limitations in the Windows socket API.
i need to debug a program i wrote in Eclipse with PyDev plugin. However I can not debug it because Eclipse obviously does not have the permission to do so.
I always get the following error when debugging reaches the send() function.
socket.error: [Errno 1] Operation not permitted
Running Eclipse with gksudo does not work either. It opens, but it says the editor could not be found.
Could not open the editor: No editor descriptor for id
org.python.pydev.editor.PythonEditor
How do I fix this?
I can't post the full code, it's too long. Here is a kind of breakdown, which causes the same error. Eclipse is not allowed the execute the send() function. Executing it with sudo in the command shell works.
from scapy.all import *
from scapy.layers.inet import IP, UDP
class SomeIP(Packet):
name = "SomeIP Packet"
fields_desc=[XShortField("X", 0x1000),
XShortField("Y", 0x1000)]
SIP = SomeIP()
packet = IP(src="129.168.101.164",dst="192.168.101.143")/UDP(sport=1000, dport=1000)/SIP
send(packet, verbose=False)
Here is the error I get - the first line can be ignored.
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
File "scapy_test.py", line 19, in <module>
send(packet, verbose=False)
File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 251, in send
__gen_send(conf.L3socket(*args, **kargs), x, inter=inter, loop=loop, count=count,verbose=verbose, realtime=realtime)
File "/usr/lib/python2.7/dist-packages/scapy/arch/linux.py", line 307, in __init__
self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type))
File "/usr/lib/python2.7/socket.py", line 187, in __init__
_sock = _realsocket(family, type, proto)
socket.error: [Errno 1] Operation not permitted
Could you use another port number? If I understand your code correctly you try to open a port on number 1000. Since port numbers up to 1024 can only be used by root, setting the port number to something higher than 1024 could maybe solve the problem.
I'm getting the error:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at
(http://www.w3.org/2001/XMLSchema.x sd), failed
when passing a Doctor (constructed with ImportDoctor) to the suds Client constructor.
I'm working on two Windows machines, both of them got the same version of suds installed, but only one of them rises the error above.
Could someone guide me here to know why this error rises?, so I can figure out what's missing on the machine where it happens?.
Thanks in advance!!!.
UPDATE: I don't really know if this is important, but it's worth noting that my Windows machine that is rising the error is an Amazon Web Services instance. At my local machine everything's working well!.
UPDATE: Here's some code I ran at the python interpreter of the machine I mentioned. Here you can detail how the error is rising...
>>> from suds.client import Client
>>> from suds.xsd.doctor import ImportDoctor, Import
>>> missing_import = Import("http://www.w3.org/2001/XMLSchema")
>>> missing_import.filter.add("http://tempuri.org/")
>>> doctor = ImportDoctor(missing_import)
>>> client = Client("http://etcfulfill.ebooks.com/Fulfillment.asmx?wsdl")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "suds\client.py", line 112, in __init__
self.wsdl = reader.open(url)
File "suds\reader.py", line 152, in open
d = self.fn(url, self.options)
File "suds\wsdl.py", line 159, in __init__
self.build_schema()
File "suds\wsdl.py", line 220, in build_schema
self.schema = container.load(self.options)
File "suds\xsd\schema.py", line 95, in load
child.dereference()
File "suds\xsd\schema.py", line 323, in dereference
midx, deps = x.dependencies()
File "suds\xsd\sxbasic.py", line 422, in dependencies
raise TypeNotFound(self.ref)
suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
>>> client = Client("http://etcfulfill.ebooks.com/Fulfillment.asmx?wsdl", doctor=doctor)
No handlers could be found for logger "suds.xsd.sxbasic"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "suds\client.py", line 112, in __init__
self.wsdl = reader.open(url)
File "suds\reader.py", line 152, in open
d = self.fn(url, self.options)
File "suds\wsdl.py", line 159, in __init__
self.build_schema()
File "suds\wsdl.py", line 220, in build_schema
self.schema = container.load(self.options)
File "suds\xsd\schema.py", line 93, in load
child.open_imports(options)
File "suds\xsd\schema.py", line 305, in open_imports
imported = imp.open(options)
File "suds\xsd\sxbasic.py", line 542, in open
result = self.download(options)
File "suds\xsd\sxbasic.py", line 567, in download
raise Exception(msg)
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
UPDATE:
I realized that suds connections always open in TCP increasing ports, and if it reaches the maximum TCP port (65535) then it starts opening again from the minimum TCP port available, so there's no problem with this.
The problem shows up when using suds ImportDoctor, because it has to open a previous connection to the location where the import should be retrieved, and for some reason, if the system reaches the maximum TCP port count, then suds somehow assumes that there's no TCP port available to open the connection for obtaining the import, and in consecuence it throws the exception:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
I repeat, this only happens if suds has to open this previous connection for obtaining the import. If ImportDoctor is not used, then suds has no problem if the TCP port count reaches its maximum, it just restarts at the minimum port available.
Does anyone has any clue on how to resolve this issue???. I'd really appreciate the help!!!.
I've figured out what the problem was. The schema that was missing from the WSDL I was trying to use with suds was:
http://www.w3.org/2001/XMLSchema
And the XSD file for this schema is at:
http://www.w3.org/2001/XMLSchema.xsd
So when I used suds ImportDoctor to add this schema import, sometimes the w3.org domain was denying my access (don't know why really) and that's why this error was rising:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
What did I do to solve this problem?. I just downloaded this schema to my machine and used suds ImportDoctor to retrieve this import locally.
And that was it!!!. Confusing bug!!!. But SOLVED.
I am having problems decoding this error message for the python on my Raspberry Pi. Please don't tell me to head to that SE, they sent me here as no one really knew what it means. It is from [GitHub][1]
Here is the error output:
Traceback (most recent call last):
File "/home/pi/piarduino/MissionControl-master/mcDesk.py", line 8, in <module> serialFromArduino = serial.Serial("/dev/serial/by-id/usb-FTDI_FTDI_FT232R_USB_UART_A900aepy-if800-port0", 115200)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 276, in open
raise SerialException("could not open por %s: %s" % (self._port, msg))
SerialException: could not open port /dev/serial/by-id/usb-FTDI_FTDI_FT232R_USB_UART_A900aepy-if800-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-FTDI_FTDI_FT232R_USB_UART_A900aepy-if800-port0'
Basic troubleshooting:
Try running your script as root using sudo. It's possible you're being denied access to the serial port.
Run ls /dev/serial/by-id in a shell. Make sure the serial port you are trying to open exists and matches exactly with the port you're trying to open in your program.
If neither of those options work, try these steps.
If you care to update your question with more details, we may be able to help you further.