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