【发布时间】:2015-10-31 08:52:16
【问题描述】:
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)
我使用 Python 2.7 我得到 AttributeError: 'str' object has no attribute '_request' 回溯错误显示 Shodan API 的 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'
【问题讨论】:
-
很明显,您传递了一个字符串 - 命令行参数与空格连接 - 作为父级,而 Exploits 类期望具有 _request 参数的其他内容。你应该阅读你的 api 的文档来看看是什么。
-
我对 Shodan 不熟悉,但看起来你应该使用
api.exploits而不是api.Exploits。