Skip to content

Shodan API Error: Unable to parse JSON response #227

@coder3119

Description

@coder3119

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions