import shodan
import sys
from ConfigParser import ConfigParser
#grab the api key from auth.ini
config = ConfigParser()
config.read('auth.ini')
SHODAN_API_KEY = config.get('auth','API_KEY')
#initialize the api object
api = shodan.Shodan(SHODAN_API_KEY)\
# Input validation
if len(sys.argv) == 1:
print 'Usage: %s <search query>' % sys.argv[0]
sys.exit(1)
try:
query = ' '.join(sys.argv[1:])
parent = query
exploit = api.Exploits(parent)
#WHY DOESNT THIS WORK
#AttributeError: 'str' object has no attribute '_request'
print exploit.search(query)
except Exception, e:
print 'Error: %s' % e
sys.exit(1)我使用Python2.7获得了AttributeError:'str‘对象没有属性'_request’跟踪错误显示在Shodan中的client.py中的第79行,是只有我还是他们的代码不可靠?
这是回溯
Traceback (most recent call last):
File "exploitsearch.py", line 26, in <module>
print exploit.search('query')
File "/usr/local/lib/python2.7/dist-packages/shodan/client.py", line 79, in search
return self.parent._request('/api/search', query_args, service='exploits')
AttributeError: 'str' object has no attribute '_request'发布于 2015-10-31 00:52:16
我是Shodan的创始人,也是你正在使用的相关图书馆的作者。以上约翰·戈登提供了正确的答案:
您不需要实例化利用类,它是在创建Shodan()实例时自动完成的。这意味着你可以直接搜索东西而不需要做任何额外的工作:
api = shodan.Shodan(YOUR_API_KEY)
results = api.exploits.search('apache')发布于 2015-10-30 17:05:59
parent变量应该是Shodan类型的。您正在使用Exploits变量初始化string类。这是您给您带来问题的行,https://github.com/achillean/shodan-python/blob/master/shodan/client.py#L79。
发布于 2015-10-30 17:06:34
Exploits是Shodan超类的子类。这个类有一个名为_request的方法。初始化Exploits实例并执行search方法时,代码内部调用超级(read:Shodan)方法_request。由于您将字符串类型传递给类构造函数,所以它试图对string对象调用此方法,并(正确地)抱怨该方法不是str的成员。
这是git回购。在第79行中,您可以看到调用发生的位置:
return self.parent._request('/api/search', query_args, service='exploits')因此,您可以看到您的parent变量应该是Shodan的一个实例,或者您的api变量。
https://stackoverflow.com/questions/33441054
复制相似问题