From 86dd3db08a481e956ab95571f0a36845eea0bbe0 Mon Sep 17 00:00:00 2001 From: frxz751113 <156018267+frxz751113@users.noreply.github.com> Date: Tue, 27 Aug 2024 00:51:20 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E6=94=B6=E9=9B=86.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- py/收集.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py/收集.py b/py/收集.py index c7fe129..0358e57 100644 --- a/py/收集.py +++ b/py/收集.py @@ -415,7 +415,7 @@ from urllib.parse import urlparse from tqdm import tqdm # 测试HTTP连接并尝试下载数据 -def test_connectivity_and_download(url, initial_timeout=0.3, retry_timeout=0.8): +def test_connectivity_and_download(url, initial_timeout=0.3, retry_timeout=1): parsed_url = urlparse(url) if parsed_url.scheme not in ['http', 'https']: # 非HTTP(s)协议,尝试RTSP检测 @@ -424,10 +424,10 @@ def test_connectivity_and_download(url, initial_timeout=0.3, retry_timeout=0.8): # HTTP(s)协议,使用原始方法 try: with requests.get(url, stream=True, timeout=initial_timeout) as response: - if response.status_code == 200: + if 200 <= response.status_code <= 402: start_time = time.time() while time.time() - start_time < initial_timeout: - chunk = response.raw.read(512) # 尝试下载1KB数据 + chunk = response.raw.read(128) # 尝试下载1KB数据 if chunk: return True # 成功下载数据 except requests.RequestException as e: