How to check HTTP errors for more than two URLs?
<p><strong><em>Question: I've 3 URLS - testurl1, testurl2 and testurl3. I'd like to try testurl1 first, if I get 404 error then try testurl2, if that gets 404 error then try testurl3. How to achieve this? So far I've tried below but that works only for two url, how to add support for third url?</em></strong></p>

<pre><code>from urllib2 import Request, urlopen
from urllib2 import URLError, HTTPError

def checkfiles():
    req = Request('http://testurl1')
    try:
        response = urlopen(req)
        url1=('http://testurl1')

    except HTTPError, URLError:
        url1 = ('http://testurl2')

    print url1
    finalURL='wget '+url1+'/testfile.tgz'

    print finalURL

checkfiles()
</code></pre>

<p>Hmmm maybe something like this?</p>

<pre><code>from urllib2 import Request, urlopen
from urllib2 import URLError, HTTPError

def checkfiles():
    req = Request('http://testurl1')
    try:
        response = urlopen(req)
        url1=('http://testurl1')

    except HTTPError, URLError:
        try:
            url1 = ('http://testurl2')
        except HTTPError, URLError:
            url1 = ('http://testurl3')
    print url1
    finalURL='wget '+url1+'/testfile.tgz'

    print finalURL

checkfiles()
</code></pre>

python http-error