Python urllib timeout error even with headers for certain websites
Question: I'm writing a simple Python 3 script to retrieve HTML data. Here's my test
script:

    
    
    import urllib.request
    
    url="http://techxplore.com/news/2015-05-audi-r8-e-tron-aims-high.html"
    
    req = urllib.request.Request(
        url, 
        data=None, 
        headers={
            'User-agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11',
            'Referer': 'http://www.google.com'
        }
    )
    
    f = urllib.request.urlopen(req)
    

This works fine for most websites but returns the following error for certain
ones:

    
    
    urllib.error.URLError: <urlopen error [Errno 110] Connection timed out>
    

The URL shown in the script is one of the sites that returns this error. Based
on research from other posts and sites, it seems like manually setting the
user-agent and/or the referer should solve the problem, but this script still
times out. I'm not sure why this is occurring only for certain websites, and I
don't know what else to try. I wold appreciate any suggestions the community
could offer.


Answer: I tried the script again today without changing anything, and it worked
perfectly. Looks like it was just something strange going on with the remote
web server.

