shodan-python
shodan-python copied to clipboard
Add timeout to requests in Shodan._request()
I've noticed that when facing network problems (e.g. Wi-Fi connection dropped) Shodan may hang indefinitely without timing out. The code calling the Shodan library has no control over this and may be left hanging for a response.
According to the requests
documentation requests should have a timeout:
Most requests to external servers should have a timeout attached, in case the server is not responding in a timely manner. By default, requests do not time out unless a timeout value is set explicitly. Without a timeout, your code may hang for minutes or more.
These changes define a REQUESTS_TIMEOUT
constant which defines a connect and read timeout of 30 seconds each. These timeouts are applied to the _request()
method of the Shodan
class.