Proper Handling Connection Error: Connection aborted, BadStatusLine(" ' ",)
<p>I have been querying data on a web server using the <code>requests</code> library in Python. I get the following error: </p>

<pre><code>ConnectionError: ('Connection aborted.', BadStatusLine("''",))
</code></pre>

<p>I would like my program <strong>not</strong> to abort but test the connection and continue from where it left off. How should I do this? </p>

<p>I have the following code in a function called <code>query_predix_ts</code> that queries the web server: </p>

<pre><code>r_s = requests.post(url, data=json.dumps(payload2), headers=header_store)
</code></pre>

<p>Here's the function call: </p>

<pre><code>for tag in tags_list:
                if tag in tags_with_dim_list:
                    for dim in dims:
                        try:
                            df = query_predix_ts(t1, t2, tag, 0, this_msk, dim)
                        except(ValueError, NameError) as e:
                            print e
                        if df.shape[0] != 0:
                            sensor_type = tag + dim
                            df['sensor_type'] = sensor_type
                            # print df.head()
                            single_df.append(df)
</code></pre>

<p>How should I wrap this line within the try-exception so when there is connection error, it continues to try, say 5 times before it aborts? </p>