Python: Urllib2 | [Errno 54] Connection reset by peer

不问归期 提交于 2019-12-02 03:38:15

问题


I'm calling a list of urls from the same domain and returning a snip of their html for a few thousand domains but am getting this error about 1,000 rows or so in.

  • Is there anything I can do to avoid this error?
  • Does it make sense to create a wait step after every row? every few hundred rows?
  • Is there a better way to get around this?

      File "/Users.../ap.py", line 144, in <module> simpleProg()
      File "/Users.../ap.py", line 21, in simpleProg()
      File "/Users.../ap.py", line 57, in first_step()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
        return _opener.open(url, data, timeout)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 400, in open
        response = self._open(req, data)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 418, in _open 
        '_open', req)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 378, in _call_chain
        result = func(*args)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1207, in http_open
        return self.do_open(httplib.HTTPConnection, req)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1180, in do_open
        r = h.getresponse(buffering=True)
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1030, in getresponse
        response.begin()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 407, 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()
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 447, in readline
        data = self._sock.recv(self._rbufsize)
        socket.error: [Errno 54] Connection reset by peer
    

来源:https://stackoverflow.com/questions/21334966/python-urllib2-errno-54-connection-reset-by-peer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!