Python爬虫出现错误:ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。

Python 专栏收录该内容
63 篇文章 1 订阅
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\APP\pycharm\PyCharm 2018.2.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 194, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\APP\pycharm\PyCharm 2018.2.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "E:/azjp/python3/luxian_nforn.py", line 152, in <module>
    res_bus = urlopen(aurl_bus)
  File "D:\python366\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "D:\python366\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)
  File "D:\python366\lib\urllib\request.py", line 544, in _open
    '_open', req)
  File "D:\python366\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "D:\python366\lib\urllib\request.py", line 1346, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "D:\python366\lib\urllib\request.py", line 1321, in do_open
    r = h.getresponse()
  File "D:\python366\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "D:\python366\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "D:\python366\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "D:\python366\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。

分析原因,可能是因为使用urlopen打开网页太过频繁,引起远程主机的怀疑,被认定为是攻击行为。导致执行urlopen()后,request. read()一直卡死在那里,最后抛出异常。

这个错误是connection reset by peer.也就是传说的远端主机重置了此连接。原因可能是socket超时时间过长;request = urllib.request.urlopen(url)之后,没有进行request.close()操作;无sleep间隔,导致网站认定这种行为是攻击。

  • 1
    点赞
  • 3
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值