Python错误转义“socket.error:[Errno 54]连接由同行重置”

时间:2014-07-27 18:19:00

标签: python error-handling urllib2

我正在运行一个经过一些域名的刮刀,它正挂在http://www.1000markets.com/

从不同的来源检查它似乎已经失效。这完全没问题,但是我收到了标题中提到的错误。

我怎么能逃避这个?我正在使用HTTPerror和URLerror,但它仍然被挂起。

对此的任何帮助都很棒

def get_html(link):
    import urllib2
    from urllib2 import Request, urlopen, URLError, HTTPError
    try:
        res = urllib2.urlopen(link)
        html = res.read()       

    except URLError as e:
        return link

    except HTTPError as e:
        return link

编辑:附件是错误

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
  return _opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 404, in open
  response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 422, in _open
  '_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
  result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1214, in http_open
  return self.do_open(httplib.HTTPConnection, req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1187, in do_open
  r = h.getresponse(buffering=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1045, in getresponse
  response.begin()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 409, in begin
  version, status, reason = self._read_status()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 365, in _read_status
  line = self.fp.readline(_MAXLINE + 1)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 476, in readline
  data = self._sock.recv(self._rbufsize)
socket.error: [Errno 54] Connection reset by peer

0 个答案:

没有答案