AttributeError: object 'str' does not have attribute '_request' for shodan api

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)

I use Python 2.7 I get an AttributeError object: 'str' does not have the attribute '_request' traceback error shows line 79 in client.py in the Shodan API, is it just me or their code is inconvenient?

here is Traceback

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'
+4
source share
3 answers

I am the founder of Shodan and the author of the corresponding library that you use. The correct answer is provided by John Gordon above:

You do not need to create an instance of the Exploits class, it runs automatically when you create an instance of Shodan (). This means that you can directly search for things without extra work:

    api = shodan.Shodan(YOUR_API_KEY)
    results = api.exploits.search('apache')
+3

Exploits Shodan. _request. Exploits search, super (read: Shodan), _request. , () , str.

git repo. 79 , :

return self.parent._request('/api/search', query_args, service='exploits')

So you can see that your variable parentmust be an instance of Shodan or your variable api.

0
source

Source: https://habr.com/ru/post/1613872/


All Articles