Posts: 77 Threads: 19 Joined: Apr 2020 I am going through this Book "Complete Guide to Shodan" and there is this code but it doesn't work import shodan api = shodan.Shodan('myapikeyhere') # Wrap the request in a try/ except block to catch errors try: results = api.search('apache') print('Results found: %s' % results['total']) for result in results['matches']: print('IP: %s' % result['ip_str']) print(result['data']) print('') except shodan.APIError, e: print('Error: %s' % e)The error I am getting except shodan.APIError, e: ^^^^^^^^^^^^^^^^^^ SyntaxError: multiple exception types must be parenthesized Posts: 7,398 Threads: 123 Joined: Sep 2016 Jul-16-2022, 06:34 PM (This post was last modified: Jul-16-2022, 06:35 PM by snippsat.) There is some old Python 2 code in there,maybe the book is a little old and not updated. In Python 3 must do it like this: except shodan.APIError as e: Updated with newer string formatting f-string. import shodan api = shodan.Shodan('myapikeyhere') # Wrap the request in a try/ except block to catch errors try: results = api.search('apache') print(f"Results found: {results['total']}") for result in results['matches']: print(f"IP: {result['ip_str']}") print(result['data']) print('') except shodan.APIError as error: print(f'Error: {error}') Posts: 77 Threads: 19 Joined: Apr 2020 Jul-16-2022, 07:08 PM (This post was last modified: Jul-16-2022, 07:08 PM by Calli.) (Jul-16-2022, 06:34 PM)snippsat Wrote: There is some old Python 2 code in there,maybe the book is a little old and not updated. In Python 3 must do it like this: except shodan.APIError as e: Updated with newer string formatting f-string. import shodan api = shodan.Shodan('myapikeyhere') # Wrap the request in a try/ except block to catch errors try: results = api.search('apache') print(f"Results found: {results['total']}") for result in results['matches']: print(f"IP: {result['ip_str']}") print(result['data']) print('') except shodan.APIError as error: print(f'Error: {error}') I'm getting this error what could be the reason AttributeError: partially initialized module 'shodan' has no attribute 'Shodan' (most likely due to a circular import). Did you mean: 'shodan'? I have shodan install pip install shodan Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: shodan in /usr/local/lib/python3.10/dist-packages/shodan-1.27.0-py3.10.egg (1.27.0) Requirement already satisfied: XlsxWriter in /usr/lib/python3/dist-packages (from shodan) (3.0.2) Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from shodan) (7.0) Requirement already satisfied: click-plugins in /usr/lib/python3/dist-packages (from shodan) (1.1.1) Requirement already satisfied: colorama in /usr/lib/python3/dist-packages (from shodan) (0.4.5) Requirement already satisfied: requests>=2.2.1 in /usr/local/lib/python3.10/dist-packages (from shodan) (2.28.0) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.2.1->shodan) (2.7) Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.2.1->shodan) (2020.6.20) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.2.1->shodan) (1.24.3) Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/lib/python3/dist-packages (from requests>=2.2.1->shodan) (2.0.6) python3 -m pip install shodan Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: shodan in /usr/local/lib/python3.10/dist-packages/shodan-1.27.0-py3.10.egg (1.27.0) Requirement already satisfied: XlsxWriter in /usr/lib/python3/dist-packages (from shodan) (3.0.2) Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from shodan) (7.0) Requirement already satisfied: click-plugins in /usr/lib/python3/dist-packages (from shodan) (1.1.1) Requirement already satisfied: colorama in /usr/lib/python3/dist-packages (from shodan) (0.4.5) Requirement already satisfied: requests>=2.2.1 in /usr/local/lib/python3.10/dist-packages (from shodan) (2.28.0) Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/lib/python3/dist-packages (from requests>=2.2.1->shodan) (2.0.6) Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.2.1->shodan) (2020.6.20) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.2.1->shodan) (2.7) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.2.1->shodan) (1.24.3) Posts: 7,398 Threads: 123 Joined: Sep 2016 (Jul-16-2022, 07:08 PM)Calli Wrote: I'm getting this error what could be the reason See if you have named a script shodan.py and rename or delete it. >>> import shodan >>> >>> dir(shodan) ['APIError', 'Shodan', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'client', 'exception', 'helpers', 'stream'] >>> shodan.Shodan('myapikeyhere') <shodan.client.Shodan object at 0x000001E23C9BA8C0> >>> shodan.Shodan.Dns <class 'shodan.client.Shodan.Dns'> Posts: 77 Threads: 19 Joined: Apr 2020 (Jul-16-2022, 07:35 PM)snippsat Wrote: (Jul-16-2022, 07:08 PM)Calli Wrote: I'm getting this error what could be the reason See if you have named a script shodan.py and rename or delete it. >>> import shodan >>> >>> dir(shodan) ['APIError', 'Shodan', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'client', 'exception', 'helpers', 'stream'] >>> shodan.Shodan('myapikeyhere') <shodan.client.Shodan object at 0x000001E23C9BA8C0> >>> shodan.Shodan.Dns <class 'shodan.client.Shodan.Dns'> My output >>> import shodan >>> dir(shodan) ['APIError', 'Shodan', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'client', 'exception', 'helpers', 'stream'] >>> shodan.Shodan('myapikeyhere') <shodan.client.Shodan object at 0x7fed4f96bd60> >>> shodan.Shodan.Dns <class 'shodan.client.Shodan.Dns'> >>> |