shodan-python icon indicating copy to clipboard operation
shodan-python copied to clipboard

[Chore] Rewrite the documentation examples for python 3

Open noraj opened this issue 6 years ago • 2 comments

Issue

Python 2 is deprecated but all examples in the documentation are given for python 2 rather than for python 3.

Most people use python 3 and those still using python 2 should really move to python 3 now it is deprecated. Keeping the documentation for python 2 make no sense anymore.

Solution

Rewrite the documentation examples for python 3

Example

At https://shodan.readthedocs.io/en/latest/tutorial.html#searching-shodan

# Wrap the request in a try/ except block to catch errors
try:
        # Search Shodan
        results = api.search('apache')

        # Show the results
        print('Results found: {}'.format(results['total']))
        for result in results['matches']:
                print('IP: {}'.format(result['ip_str']))
                print(result['data'])
                print('')
except shodan.APIError, e:
        print('Error: {}'.format(e))

But except shodan.APIError, e: is python 2 only. With python 3 you will get the following error:

    except shodan.APIError, e:
                          ^
SyntaxError: invalid syntax

In python 3 you should write:

except shodan.APIError as e:
    print('Error: {}'.format(e))

noraj avatar Jan 25 '20 16:01 noraj

Fix tracking:

  • [x] #115
  • [x] #116
  • [x] #117

noraj avatar Jan 25 '20 17:01 noraj

The readthedocs still needs to be updated - https://shodan.readthedocs.io/en/latest/tutorial.html

corbanvilla avatar Oct 25 '22 07:10 corbanvilla