Perhaps place the try..except block higher up in the chain of command: import collections def download_file(url): # Bundle together the bunch of browser calls necessary to download one file. browser.follow_link(…)…Read moreRecovering from ECONNRESET in Python/Mechanize