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

Shodan API Error: Unable to parse JSON response

Open coder3119 opened this issue 1 year ago • 1 comments

Shodan API Error: Unable to parse JSON response

I'm encountering an error with the shodan-python library. My code worked yesterday but is now failing, despite no changes being made.

Here is a test code that produces the same error.

import shodan
import json

# Replace with your Shodan API key
SHODAN_API_KEY = 'KEY_HERE'

def search_shodan():
    try:
        # Initialize the Shodan API client
        api = shodan.Shodan(SHODAN_API_KEY)
        
        # Perform the search
        query = 'QUERY_HERE'
        results = api.search(query)
        
        # Print total results found
        print(f'Results found: {results["total"]}')
        
        # Iterate through the results and print raw data
        for result in results['matches']:
            print('\n------------------------')
            print(f'IP: {result["ip_str"]}')
            print(f'Port: {result["port"]}')
            print(f'Organization: {result.get("org", "N/A")}')
            print(f'Location: {result["location"]["country_name"]}')
            print(f'Hostnames: {result.get("hostnames", [])}')
            print('\nRaw Data:')
            print(json.dumps(result, indent=2))
            
    except shodan.APIError as e:
        print(f'Error: {e}')

if __name__ == '__main__':
    search_shodan()

coder3119 avatar Nov 30 '24 01:11 coder3119

@coder3119 Could you share the query used, exact error that is occurring, as well as the stack trace?

rmhowe425 avatar Feb 02 '25 17:02 rmhowe425