Python urllib和防火墙:“连接被强制关闭”

时间:2012-11-29 21:08:10

标签: python web-scraping firewall

我正在编写The Programming Historian 2,这是一个关于HTML和Python的历史学家编码的自学教程。我正在尝试完成“使用文件和网页”课程,但我仍然坚持使用Python单元打开URL。我正在运行以下程序:

# open-webpage.py

import urllib2

url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'

response = urllib2.urlopen(url)
webContent = response.read()

print webContent[0:300]

每次运行程序时,Komodo Edit 7都会返回以下错误消息:

Traceback (most recent call last):  
  File "open-webpage.py", line 7, in <module>  
    response = urllib2.urlopen(url)  
  File "C:\Python27\lib\urllib2.py", line 126, in urlopen  
    return _opener.open(url, data, timeout)  
  File "C:\Python27\lib\urllib2.py", line 400, in open  
    response = self._open(req, data)  
  File "C:\Python27\lib\urllib2.py", line 418, in _open  
    '_open', req)  
  File "C:\Python27\lib\urllib2.py", line 378, in _call_chain  
    result = func(*args)  
  File "C:\Python27\lib\urllib2.py", line 1207, in http_open  
    return self.do_open(httplib.HTTPConnection, req)  
  File "C:\Python27\lib\urllib2.py", line 1180, in do_open  
    r = h.getresponse(buffering=True)  
  File "C:\Python27\lib\httplib.py", line 1030, in getresponse  
    response.begin()  
  File "C:\Python27\lib\httplib.py", line 407, in begin  
    version, status, reason = self._read_status()  
  File "C:\Python27\lib\httplib.py", line 365, in _read_status  
    line = self.fp.readline()  
  File "C:\Python27\lib\socket.py", line 447, in readline  
    data = self._sock.recv(self._rbufsize)  
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host

我尝试使用多个不同的网址,但总是有相同的结果。 Komodo的人认为问题与我大学的防火墙有关,因为我通过我大学的代理访问互联网。这里的技术人员告诉我将我的默认浏览器从RockMelt(铬)更改为IE,因为只有IE完全支持。我这样做没有改变,他们没有其他建议。

有人可以提出错误的替代解释或解决防火墙问题的方法吗?感谢。

0 个答案:

没有答案