Gping must be called as first argument

Asked

Viewed 96 times

2

if __name__ == '__main__':
top_100_domains = ['google.com','facebook.com','youtube.com','yahoo.com','baidu.com','wikipedia.org','live.com','qq.com','twitter.com','amazon.com','linkedin.com','blogspot.com','google.co.in','taobao.com','sina.com.cn','yahoo.co.jp','msn.com','google.com.hk','wordpress.com','google.de','google.co.jp','google.co.uk','ebay.com','yandex.ru','163.com','google.fr','weibo.com','googleusercontent.com','bing.com','microsoft.com','google.com','babylon.com','soso.com','apple.com','mail.ru','t.co','tumblr.com','vk.com','google.ru','sohu.com','google.es','pinterest.com','google.it','craigslist.org','bbc.co.uk','livejasmin.com','tudou.com','paypal.com','blogger.com','xhamster.com','ask.com','youku.com','fc2.com','google.com.mx','xvideos.com','google.ca','imdb.com','flickr.com','go.com','tmall.com','avg.com','ifeng.com','hao123.com','zedo.com','conduit.com','google.co.id','pornhub.com','adobe.com','blogspot.in','odnoklassniki.ru','google.com.tr','cnn.com','aol.com','360buy.com','google.com.au','rakuten.co.jp','about.com','mediafire.com','alibaba.com','ebay.de','espn.go.com','wordpress.org','chinaz.com','google.pl','stackoverflow.com','netflix.com','ebay.co.uk','uol.com.br','amazon.de','ameblo.jp','adf.ly','godaddy.com','huffingtonpost.com','amazon.co.jp','cnet.com','globo.com','youporn.com','4shared.com','thepiratebay.se','renren.com']
gp = GPing
for domain in top_100_domains:
    gp.send(domain,test_callback)
gp.join()

ERROR:

gp.send(Domain,test_callback) Typeerror: Unbound method send() must be called with Gping instance as first argument (got str instance Instead)

  • Are you using Python 3 or Python 2? Try using it like this gp = GPing()

  • I’m using the 2, I put the parentheses and presents another error, previously I was with and I took to try to solve.

  • And what would this other mistake be?

  • raise socket.error(msg) socket.error: Operation not permitted - Note that ICMP messages can only be sent from processes running as root.

  • Yulia try to run as root, if it’s Debian or Ubuntu try sudo

  • I’ll try to!!!!!

Show 1 more comment

1 answer

3


The error happens because you are calling the method statically without instantiating the class. While doing:

gp = GPing

You are not creating a class instance, but passing the class reference to another object. To correct, simply insert the parentheses:

gp = GPing()

You can check this by displaying the object gp.

>>> gp = GPing
>>> print(gp)
<class 'GPing'>

But in doing:

>>> gp = GPing()
>>> print(gp)
<GPing object at 0x...>

Notice that in the first way, gp refers to the class GPing while the second refers to object of the same class.

The error itself happens because the method send should be defined as:

def send(self, domain, callback):
    ...

In which self is the class instance itself GPing. Calling the method without creating the instance, the first argument of the method is not set automatically and therefore a type error is generated.

Related questions

Why do we have to use the self attribute as an argument in the methods?

In Python, there is some rule or advantage regarding the use of 'Self''?

How to call an external function without sending the 'self'?

  • Was faster than me, I imagined that it was this same, but being Python2 I was not sure, I use the 3. +1

  • I already signaled as a typo too, but I decided to answer because I think some languages allow the instance without using parentheses.

  • I think she has another problem :/ http://answall.com/questions/194319/gping-deve-beingcalled as first argument?noredirect=1#comment400823_194319

Browser other questions tagged

You are not signed in. Login or sign up in order to post.