Inconsistent HTTP Connnection

I haven't had a chance to work on this project for the past few days, but I tried using my original code (with a few modifications) as well as zoomkat's. Both seem to give me mixed results as far as connectivity. With zoomkat's, sometimes it connects and downloads a page immediately after I press 'e', other times it takes around 20 seconds before it says connection failed.

I originally had things set up in a for loop so that it would keep trying over and over again. This seemed to provide okay results, but also seemed like a work-around with addressing the actual problem.