Several times I've seen mention that for asynchronous ping is good to use twisted.
I written implementation on threads (like Ping a site in Python?)
But on ~200 threads i have crush
On page http://twistedmatrix.com/trac/wiki/ProjectsUsingTwisted i find
txNetTools - Ping, traceroute, icmp, etc., implemented in Twisted, and a library for those who want to build their own network tools.
Has anyone used this library?
I tried to use it ping.py:
Traceback (most recent call last):
File "ping.py", line 23, in <module>
class Pinger(ICMP):
NameError: name 'ICMP' is not defined
if change:
class Pinger(**ICMP**):
to
class Pinger():
Traceback (most recent call last):
File "ping.py", line 54, in <module>
reactor.listenICMP(0, Pinger())
File "./txnet/reactor.py", line 21, in listenICMP
p.startListening()
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/udp.py", line 102, in startListening
self._connectToProtocol()
File "/usr/local/lib/python2.7/dist-packages/twisted/internet/udp.py", line 123, in _connectToProtocol
self.protocol.makeConnection(self)
AttributeError: Pinger instance has no attribute 'makeConnection'
Maybe I'm doing something wrong or not understand?
P.S. twisted 12.0
If you are running sandbox/ping.py, then the exception you report doesn't make sense. That file has this import near the beginning:
from txnet.icmp import ICMP, Packet, ECHO_REQUEST
This defines the ICMP name. The Pinger class comes later, extending it. I can successfully run this demo program (though it fails with an unrecognized message type when handling the response on my sytem).
Perhaps you have an old version of the code, or have modified it somehow, or are running a different ping.py?
Related
Hi I'm a beginner with Python and Scapy. When I try to use sendp() on a basic Layer 2 packet, I get a traceback error.
Using Python 3.8 and the latest development version of Scapy from https://scapy.readthedocs.io/en/latest/installation.html#platform-specific-instructions
This is what I'm inputting into the Python shell:
import scapy
from scapy.all import *
a=Ether()/IP(dst="www.google.ca")/ICMP()/"Hello world"
sendp(a)
This is the error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
sendp(a)
File "C:\Users\hoang\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scapy-git_archive.dev304758016-py3.8.egg\scapy\sendrecv.py", line 336, in sendp
results = __gen_send(socket, x, inter=inter, loop=loop,
File "C:\Users\hoang\AppData\Local\Programs\Python\Python38-32\lib\site-packages\scapy-git_archive.dev304758016-py3.8.egg\scapy\sendrecv.py", line 296, in __gen_send
os.write(1, b".")
OSError: [Errno 9] Bad file descriptor
As pointed by #furas, this is indeed an issue with your console (IDLE?).
Scapy tries to display that the packet was sent, which fails.
You can always use
sendp(p, verbose=False)
To disable the logs, therefore working around the issue.
However I must say that if os.write(1, ..) was the only option back in the days, it's a bit outdated nowadays. This could probably be fixed on upstream.
I am trying to write some code to perform some packet sniffing with python
using pyshark.I have the following piece of code:
import pyshark
print('Pyshark demo')
capture = pyshark.LiveCapture(interface='enp0s8')
However when I try to run this script I get the following stack trace:
Pyshark demo
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/lib/python3.5/asyncio/base_events.py", line 431, in __del__
File "/usr/lib/python3.5/asyncio/unix_events.py", line 58, in close
File "/usr/lib/python3.5/asyncio/unix_events.py", line 139, in remove_signal_handler
File "/usr/lib/python3.5/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object
I have install pyshark.Do you have any idea what is causing this problem?
I run this on an ubuntu server 16.04
It is related to python issues:
https://bugs.python.org/issue26133
https://bugs.python.org/issue23548
https://bugs.python.org/issue28628?#ok_message=file%2045378%20created%0Amsg%20280182%20created%0Aissue%2028628%20created&#template=item
also see:
Trigger catkin build process from within python
I have a few twitterbots that I run on my raspberryPi. I have most functions wrapped in a try / except to ensure that if something errors it doesn't break the program and continues to execute.
I'm also using Python's Streaming library as my source of monitoring for the tags that I want the bot to retweet.
Here is an issue that happens that kills the program although I have the main function wrapped in a try/except:
Unhandled exception in thread started by <function startBot5 at 0x762fbed0>
Traceback (most recent call last):
File "TwitButter.py", line 151, in startBot5
'<botnamehere>'
File "/home/pi/twitter/bots/TwitBot.py", line 49, in __init__
self.startFiltering(trackList)
File "/home/pi/twitter/bots/TwitBot.py", line 54, in startFiltering
self.myStream.filter(track=tList)
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 445, in filter
self._start(async)
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 361, in _start
self._run()
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 294, in _run
raise exception
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 263, in _run
self._read_loop(resp)
File "/usr/local/lib/python3.4/dist-packages/tweepy/streaming.py", line 313, in _read_loop
line = buf.read_line().strip()
AttributeError: 'NoneType' object has no attribute 'strip'
My setup:
I have a parent class TwitButter.py, that creates an object from the TwitBot.py. These objects are the bots, and they are started on their own thread so they can run independently.
I have a function in the TwitBot that runs the startFiltering() function. It is wrapped in a try/except, but my except code is never triggered.
My guess is that the error is occurring within the Streaming library. Maybe that library is poorly coded and breaks on the line that is specified at the bottom of the traceback.
Any help would be awesome, and I wonder if others have experienced this issue?
I can provide extra details if needed.
Thanks!!!
This actually is problem in tweepy that was fixed by github #870 in 2017-04. So, should be resolved by updating your local copy to latest master.
What I did to discover that:
Did a web search to find the tweepy source repo.
Looked at streaming.py for context on the last traceback lines.
Noticed the most recent change to the file was the same problem.
I'll also note that most of the time you get a traceback from deep inside a Python library, the problem comes from the code calling it incorrectly, rather than a bug in the library. But not always. :)
I'm trying to get a simple Pyro example running (taken from this page), this is the code:
import Pyro.core
import Pyro.naming
class JokeGen(Pyro.core.ObjBase):
def joke(self, name):
return "Sorry "+name+", I don't know any jokes."
daemon=Pyro.core.Daemon()
ns=Pyro.naming.NameServerLocator().getNS()
daemon.useNameServer(ns)
uri=daemon.connect(JokeGen(),"jokegen")
daemon.requestLoop()
When I run this script with Python 2.6.5 and Python 2.6.6 (tried both on Ubuntu 10.04 and Debian Squeeze), I'm always getting this error:
Traceback (most recent call last):
File "/home/ingo/tools/python/pyroserver.py", line 9, in <module>
ns=Pyro.naming.NameServerLocator().getNS()
File "/usr/lib/pymodules/python2.6/Pyro/naming.py", line 176, in getNS
reply = self.sendSysCommand(NS_SYSCMD_LOCATION,host,port,trace,1,bcaddr)
File "/usr/lib/pymodules/python2.6/Pyro/naming.py", line 76, in sendSysCommand
raise Pyro.errors.NamingError("could not find NameServer")
Pyro.errors.NamingError: could not find NameServer
What's wrong with the script? How can I create that nameserver?
Run pyro-ns in another terminial first. That is the Pyro object broker.
I am trying to use PyQt's Resource System but it appears I have no clue what I am doing! I already have to application created, along with its GUI I am just trying to import some images to use with the program.
I used the QtDesigner to create the resource file and I compiled it using pyrcc4.exe. But when I attempt to import the resource file I get this error:
Traceback (most recent call last):
File "C:\Projects\main.py", line 14, in <module>
import main_rc
File "C:\Projects\main_rc.py", line 482, in <module>
qInitResources()
File "C:\Projects\main_rc.py", line 477, in qInitResources
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
TypeError: argument 2 of qRegisterResourceData() has an invalid type
What am I doing wrong?
pyrcc generates Python 2.x code by default.
Try regenerating your resource files using pyrcc with flag '-py3'