Python Requests ignoring time outs
<p>I'm trying to make some kind of a scanner with python (just for fun)</p>

<p>it will send a get request to an random ip and see if there is any answer 
the problem is that every time that the connection fails the program will stop running . 
this is the code </p>

<pre><code>import time
import requests


ips = open("ip.txt", "r")

for ip in ips:
    r = requests.get(url="http://"+ip+"/",verify=False)
    print(r.status_code)
    time.sleep(0.5)
</code></pre>

<p>this is what i get by trying just a random ip :</p>

<pre><code>requests.exceptions.ConnectionError: HTTPConnectionPool(host='177.0.0.0', port=80): Max retries exceeded with url:
</code></pre>

<p>This is throwing an error. To protect against this, use a <code>try</code>/<code>except</code> statement:</p>

<pre><code>for ip in ips:
    try:
        r = requests.get(url="http://"+ip+"/",verify=False)
        print(r.status_code)
    except requests.exceptions.RequestException as e:
        print('Connecting to ip ' + ip + ' failed.', e) 
    time.sleep(0.5)
</code></pre>

python python-requests