aspnet 远程主机强迫关闭了一个现有的连接 凤凰彩票 ConnectionResetError:[WinError 10054]很远

日期:2021-01-21 14:21:48 浏览量: 156

ConnectionResetError:[WinError 10054]现有连接已被远程主机强行关闭。

错误的结果:

Traceback (most recent call last):
  File "G:/python图片下载/dianshiju_db.py", line 25, in 
    print(imgdon("http://tupian.tupianzy.com/pic/upload/vod/2018-11-12/201811121542011934.jpg"))
  File "G:/python图片下载/dianshiju_db.py", line 22, in imgdon
    urllib.request.urlretrieve(img_url, filename=filename)
  File "E:\python\lib\urllib\request.py", line 248, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "E:\python\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "E:\python\lib\urllib\request.py", line 526, in open
    response = self._open(req, data)
  File "E:\python\lib\urllib\request.py", line 544, in _open
    '_open', req)
  File "E:\python\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "E:\python\lib\urllib\request.py", line 1346, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "E:\python\lib\urllib\request.py", line 1321, in do_open
    r = h.getresponse()
  File "E:\python\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "E:\python\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "E:\python\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "E:\python\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。

分析:该原因意味着远程用户太频繁aspnet 远程主机强迫关闭了一个现有的连接钱柜体育 ,因此远程可疑者是恶意攻击。下载远程映像时出错。我在Internet上找到的方法如下:

[Python搜寻器错误] ConnectionResetError:[WinError 10054]远程主机强行关闭了现有连接

我个人的解决方法是使用函数回调来解决

aspnet 远程主机强迫关闭了一个现有的连接_aspnet 远程主机强迫关闭了一个现有的连接_aspnet连接sql数据库 webconfig

这意味着当由于远程主机被强制关闭而导致程序报告错误时aspnet 远程主机强迫关闭了一个现有的连接yabo2020北京快乐8 ,请在报告错误重新爬网之前使用try-except再次调用该方法亚洲体育平台 ,直到爬网成功为止。通常电竞下注 ,它将成功一次或两次。效率还不错。

源代码:

aspnet 远程主机强迫关闭了一个现有的连接_aspnet 远程主机强迫关闭了一个现有的连接_aspnet连接sql数据库 webconfig

import os
import random
import urllib.request
def imgdon(url):
    img_url = url
    file_path = 'D:/book/tvimg/'
    file_name = "tvimg" + str(int(random.uniform(20, 10) * 10 ** 14))
    # 是否有这个路径
    if not os.path.exists(file_path):
        # 创建路径
        os.makedirs(file_path)
        # 获得图片后缀
    file_suffix = os.path.splitext(img_url)[1]
    # print(file_suffix)
    # 拼接图片名(包含路径)
    # filename = '{}{}{}{}'.format(file_path, os.sep, file_name, file_suffix)
    filename = file_path + file_name + file_suffix
    print(filename)
    # 下载图片,并保存到文件夹中
    urllib.request.urlretrieve(img_url, filename=filename)
    return "http://www.klkj1999.top:8081/tvimg/"+file_name + file_suffix
print(imgdon("http://tupian.tupianzy.com/pic/upload/vod/2018-11-12/201811121542011934.jpg"))

解决之后:

已解决的结果:

G:\python图片下载\venv\Scripts\python.exe G:/python图片下载/dianshiju_db.py
D:/book/tvimg/tvimg1396168651250299.jpg
D:/book/tvimg/tvimg1502497444740666.jpg
D:/book/tvimg/tvimg1103678614205344.jpg
http://www.klkj1999.top:8081/tvimg/tvimg1396168651250299.jpg
Process finished with exit code 0