Przeglądaj źródła

2024-06-11
优化重搜索逻辑
视频生成文章接口返回三条视频

罗俊辉 11 miesięcy temu
rodzic
commit
601aca4edf
1 zmienionych plików z 15 dodań i 6 usunięć
  1. 15 6
      applications/functions/common.py

+ 15 - 6
applications/functions/common.py

@@ -9,6 +9,7 @@ import random
 import hashlib
 import requests
 import aiohttp
+import asyncio
 import urllib.parse
 
 
@@ -188,13 +189,21 @@ def account_info_map(gh_id):
         return ""
 
 
-async def request_etl(url, headers, json_data):
+async def request_etl(url, headers, json_data, retries=6):
     """
-    异步请求ETL
+    :param url:
+    :param headers:
+    :param json_data:
+    :param retries:
     :return:
     """
     async with aiohttp.ClientSession() as session:
-        async with session.post(url, headers=headers, json=json_data, timeout=60) as response:
-            response_data = await response.json()
-            return response_data
-
+        for attempt in range(retries):
+            try:
+                async with session.post(url, headers=headers, json=json_data, timeout=120) as response:
+                    return await response.json()
+            except asyncio.TimeoutError:
+                if attempt < retries - 1:
+                    await asyncio.sleep(2)  # 等待一段时间后重试
+                else:
+                    raise