Przeglądaj źródła

add timeout to spider task

luojunhui 2 miesięcy temu
rodzic
commit
0d55d747ef
1 zmienionych plików z 2 dodań i 8 usunięć
  1. 2 8
      applications/search/dy_search.py

+ 2 - 8
applications/search/dy_search.py

@@ -31,8 +31,8 @@ def douyin_search(keyword, sensitive_words, trace_id):
         'Content-Type': 'application/json'
     }
 
-    response = requests.request("POST", url, headers=headers, data=payload)
     try:
+        response = requests.request("POST", url, headers=headers, data=payload, timeout=60)
         dt_list = response.json()['data']['data']
         logging(
             code="4002",
@@ -73,12 +73,6 @@ def douyin_search(keyword, sensitive_words, trace_id):
             data={"error": str(e)}
         )
         return []
-    # logging(
-    #         code="4003",
-    #         info="抖音搜索失败-搜索词:{} 原因:-{}".format(keyword, "抖查查暂停服务"),
-    #         trace_id=trace_id
-    #     )
-    # return []
 
 
 def douyin_detail(video_id):
@@ -94,7 +88,7 @@ def douyin_detail(video_id):
     headers = {
         'Content-Type': 'application/json'
     }
-    response = requests.request("POST", url, headers=headers, data=payload).json()
+    response = requests.request("POST", url, headers=headers, data=payload, timeout=60).json()
     logging(
         code="4005",
         info="抖音请求详情",