努力才能被爱慕
2018-05-08 07:32
采纳率: 66.7%
浏览 10.8k

python的requests出现10053错误,你的主机中的软件中止了一个已建立的连接。

代码:
response = requests.get(url=url, headers=headers)

是在做爬虫,昨天爬的好好的,今天就出现这个错误了,
重启爬虫,一开始能爬,过一会又出错,希望大神帮我看下

报错如下:

 Traceback (most recent call last):
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] 你的主机中的软件中止了一个已建立的连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\util\retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\urllib3\connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionAbortedError(10053, '你的主机中的软件中止了一个已建立的连接。', None, 10053, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:/temp/wosSpider/spider/main.py", line 476, in <module>
    wos_crawl.post_data()
  File "F:/temp/wosSpider/spider/main.py", line 184, in post_data
    response = requests.get(url=url, headers=headers, allow_redirects=False, )
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\longziyi\Anaconda3\envs\wos_spider\lib\site-packages\requests\adapters.py", line 490, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionAbortedError(10053, '你的主机中的软件中止了一个已建立的连接。', None, 10053, None))

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • blownewbee 2018-05-08 07:44
    已采纳

    看下你的代码的逻辑,其中打开了连接没有关闭。
    你说你的程序之前是好的,可能是你关闭连接的逻辑因为某种原因(比如超时异常)没有执行到。

    点赞 打赏 评论

相关推荐 更多相似问题