Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shodan API Error: Unable to parse JSON response #227

Open
coder3119 opened this issue Nov 30, 2024 · 0 comments
Open

Shodan API Error: Unable to parse JSON response #227

coder3119 opened this issue Nov 30, 2024 · 0 comments

Comments

@coder3119
Copy link

coder3119 commented Nov 30, 2024

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant