urllib 总是遇到超时错误

Timeout Error always encountered with urllib

我正在尝试使用 python 的 urllib class 以编程方式访问站点资源。但是,无论我使用哪个站点,我都会收到超时错误。

这段代码有什么问题?

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

错误发生在urlopen(request) 方法中。非常感谢任何帮助。

正如@dhke 所建议的那样,我实际上是在使用强制代理。