fix: 修复安徽日报出现局部变量t未定义

This commit is contained in:
皓月归尘 2024-11-12 13:27:35 +08:00
parent 9bc73843fa
commit 5767dfb591

View File

@ -76,11 +76,12 @@ async def getData(start_date: datetime, end_date: datetime):
try:
async with AsyncClient(headers=headers, timeout=60, http2=False) as client:
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), url)
try:
response = await client.get(url)
except Exception as e:
await asyncio.sleep(random.randint(8, 20))
print(f"尝试第{t + 1}次重连!")
for t in range(5):
try:
response = await client.get(url)
except Exception as e:
await asyncio.sleep(random.randint(8, 20))
print(f"尝试第{t + 1}次重连!")
response.encoding = response.charset_encoding
print(f"一级连接状态:{response.status_code}")
if response.status_code == 200: