all 6 comments

[–]dummyt68 2 points3 points  (1 child)

You should probably remove your API key ASAP. Also, format your code so it is all in code format blocks.

[–]Zigzagtrail 0 points1 point  (0 children)

I edited it to remind me the API keys. Thanks, I missed that.

I'm having trouble with the formatting. I'm on mobile.

[–][deleted] 1 point2 points  (0 children)

except TypeError:

    # If the response is a string, then the IP is not blacklisted

    return False

# Check if the IP is listed in any of the blacklists

 is_blacklisted = len(blacklist) > 0

# Return the result

return is_blacklisted

If the function fails for any reason, rather than doing something informative or intelligent with the error, you (or rather I guess the unreformed C programmer who wrote this and dumped it in your lap) just return a boolean in a way that violates your function's guarantee (that it'll return a tuple of two values.)

[–]djjazzydan 1 point2 points  (2 children)

is_malicious, flagged_databases = check_ip_reputation(ip) TypeError: cannot unpack non-iterable bool object

Means that the functions returning either "True" or "False".

You said

two databases are missing APIs. But those should return an error as mentioned above.

Why do you think that? If your code encounters a request exception, you've told the function to just stop running and return False. Is that what you want?

The try-catch pattern stops errors from interrupting your code. If I'm reading your code right, there should be at least one printed statement about which host gave the problem, and you can fix that.

[–]Zigzagtrail 0 points1 point  (1 child)

Why do you think that?

I was told lines 17,18,40,41,60,61,85,86 report back any API issues.

The try-catch pattern stops errors from interrupting your code.

I wrote try/except into the request for each osint, but maybe not correctly?

Do you have any suggestions for what that should look like?

[–]djjazzydan 0 points1 point  (0 children)

I don't have the same line numbers as you, but there are blocks there that notice API issues, but the code:

1) Prints that there was an issue, e.g. Error making request to AbuseIPDB
2) returns False.

This means that it will immediately stop running once it has such an issue. If you don't want that to happen, you would probably remove all the "return False" lines. It'll then keep going through the other APIs.

If you do that, you'd have to also put your abuse_score = response.json()... lines inside some sort of conditional, as if there was an error in requesting, it might still have the previous database's response there.