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个回答

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

qq_39457091
努力才能被爱慕 可是我使用requests的get和post都没涉及关闭连接,你的意思是我的程序影响到requests里面的连接关闭吗
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!