I'm trying to use python's urllib class to programmatically access site resources. No matter what site I use, however, I receive a timeout error.
What's wrong with this code?
url = "http://en.wikipedia.org/wiki/List_of_HTTP_header_fields"
fileLoc = "directory\\" + url.rpartition("/")[2]
request = Request(url)
request.add_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)")
response = urlopen(request)
data = response.read()
text = data.decode('utf-8')
file = open(fileLoc, "w+")
file.write(text)
file.close
The error occurs in the urlopen(request) method. Any help is greatly appreciated.