0

I need to perform a BULK whois query using shodan API.

I came across this code

import shodan
api = shodan.Shodan('inserted my API-KEY- within single quotes')
info = api.host('8.8.8.8')

After running the module i get the following error:

Traceback (most recent call last):
File "C:/Users/PIPY/AppData/Local/Programs/Python/Python37/dam.py", line 1, in
import shodan
File "C:/Users/PIPY/AppData/Local/Programs/Python/Python37\shodan.py", line 2, in
api = shodan.Shodan('the above insereted API KEY')
AttributeError: module 'shodan' has no attribute 'Shodan'

I'm learning python and have limited scripting/programming experience.

Could you please help me out?

Cheers

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
FCB
  • 1
  • 1
  • 1
  • How did you install the `shodan` library? – AKX Sep 12 '19 at 09:41
  • in the comand prompt I have used : pip install shodan then shodan init "my api key" and the o/p was " successfully initializes" – FCB Sep 12 '19 at 12:31

3 Answers3

3

You seem to have dam.py and shodan.py – Python defaults to importing from the module directory, so the installed shodan package gets masked.

Try renaming shodan.py to e.g. shodan_test.py (and of course fixing up any imports, etc.).

AKX
  • 152,115
  • 15
  • 115
  • 172
  • I have renamed the file and now I have the following error ModuleNotFoundError: No module named 'shodan'. I have tried to install it again but gives me a list of "Requirement already satisfied:" messages – FCB Sep 12 '19 at 12:57
0

I have solved the issue by re-installing the shodan module under the C:\Users\PIPY\AppData\Local\Programs\Python\Python37\Scripts>pip install shodan

Thank you for the help AKX.

FCB
  • 1
  • 1
  • 1
0

I had this same issue but after renaming my file as something different than shodan.py, I had to also delete the compiled class shodan.pyc to avoid the error.

Also, if you have more than one version of python installed, i.e. python2 and python3, use

python -m pip install shodan instead of pip install shodan, to ensure that you are installing the library in the same version of shodan that you are using to execute your script.

If you are executing your script with python3 shodan_test.py then use python3 -m pip install shodan