python list index out of range error bypassing
<p>I have a loop that runs the following code every 5 minutes, the code actually downloads a timeseries of stockprices.
Sometimes, maybe once a week I get the following error:</p>

<pre><code>Traceback (most recent call last):
  File "./regression_12_5min.py", line 284, in &lt;module&gt;
    last_price_long = listone[(len(listone)-1)][4]
IndexError: list index out of range
</code></pre>

<p>I guess, but not sure about that... that this happens because in that occasion I don't receive any  don't receive any data from the broker.</p>

<p>This is the code:</p>

<pre><code>        try:
            r = requests.get(myurl, params=price_long)

        except:
            pprint("Si e' verificato un errore")
        else:
                print "cwlong5"
            pprint(r.status_code)
            print(r.headers['content-type'])
            pprint(r.url)
                listone = crea_lista(r)

        last_price_long = listone[(len(listone)-1)][4]
        print " ultimo prezzo long" + "   " +  str(last_price_long)
</code></pre>

<p>Is my idea about the cause of the error correct?
Is there a way to bypass this error? The problem is that the raised error blocks the loop, but I would be just ok if instead of bloking itself the loop start again after other 5 minutes</p>

<p>Thanks</p>