🐛 修复当爬取数据时出现 SSLZeroReturnError 错误后无法继续爬取数据的问题

This commit is contained in:
Karako 2022-09-16 12:22:22 +08:00
parent ffb404e43b
commit 04b684bb2e
No known key found for this signature in database
GPG Key ID: 5920831B0095D4A0

View File

@ -3,6 +3,7 @@ import re
from abc import abstractmethod
from asyncio import Queue
from multiprocessing import Value
from ssl import SSLZeroReturnError
from typing import AsyncIterator, ClassVar, List, Optional, Tuple, Union
import anyio
@ -81,7 +82,7 @@ class WikiModel(Model):
for _ in range(retry_times):
try:
return await cls._client.get(url, follow_redirects=True)
except HTTPError:
except (HTTPError, SSLZeroReturnError):
await anyio.sleep(sleep)
return await cls._client.get(url, follow_redirects=True) # 防止 retry_times 等于 0 的时候无法发生请求