aag / apple_trailer_downloader

A script to download HD trailers from the Apple Trailers website.
GNU General Public License v3.0
23 stars 5 forks source link

Handle HTTP errors gracefully #12

Closed forthrin closed 8 years ago

forthrin commented 8 years ago

The script should not crash and print a full call stack when it's unable to complete a HTTP request. I think it happens rather because there is no internet connection at all, than single HTTP addresses failing.

Traceback (most recent call last):
  File "bin/apple_trailer_downloader/download_trailers.py", line 471, in <module>
    settings['video_types']
  File "bin/apple_trailer_downloader/download_trailers.py", line 246, in downloadTrailersFromPage
    downloadTrailerFile(trailerUrl['url'], destdir, trailerFileName)
  File "bin/apple_trailer_downloader/download_trailers.py", line 214, in downloadTrailerFile
    f = urllib2.urlopen(req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 437, in open
    response = meth(req, response)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
aag commented 8 years ago

HTTP errors are now handled gracefully. The script just prints an error message and goes on to the next file.