ImageNet-downloader icon indicating copy to clipboard operation
ImageNet-downloader copied to clipboard

Suggestion: Timeout for url

Open SaschaHornauer opened this issue 6 years ago • 1 comments

Hi,

I realized a lot of the URLs do take quite a long time to finally state they can not be reached. If you'd use urllib.urlopen instead of urlretrieve you can define a timeout. Like this:

try:
    request = urllib.urlopen(url, timeout=500)
    with open(os.path.join(output_folder, fname), 'wb') as f:
        f.write(request.read())		
except Exception as ex:
    print "Could not retrieve url: ", url, " | skipping" 
    print ex

I would write a pull request but I am using urllib2 and python2.7 and lack a bit of motivation to install python3 to test it adequately.

SaschaHornauer avatar Jun 21 '18 21:06 SaschaHornauer

Hey @SaschaHornauer sorry for the late reply. I remember debating whether to use urllib.urlopen or urlretrieve but I forgot why I chose urlretrieve. I'll make the changes you suggested by the end of the week. Thanks for the suggestion :smile:

akshaychawla avatar Jul 18 '18 15:07 akshaychawla