Forráskód Böngészése

抖音详情请求失败日志

luojunhui 5 hónapja
szülő
commit
818b7bc0fe
1 módosított fájl, 16 hozzáadás és 11 törlés
  1. 16 11
      applications/search/dy_search.py

+ 16 - 11
applications/search/dy_search.py

@@ -93,24 +93,29 @@ def douyin_detail(video_id):
     headers = {
     headers = {
         'Content-Type': 'application/json'
         'Content-Type': 'application/json'
     }
     }
-    print(video_id)
     response = requests.request("POST", url, headers=headers, data=payload).json()
     response = requests.request("POST", url, headers=headers, data=payload).json()
     logging(
     logging(
         code="4005",
         code="4005",
         info="抖音请求详情",
         info="抖音请求详情",
         data=response
         data=response
     )
     )
-    print(json.dumps(response,ensure_ascii=False, indent=4))
-    try:
-        video_info = response['data']['data']
-        if video_info['content_type'] == "note":
-            return None
-        else:
-            return video_info
-    except Exception as e:
+    if response['code'] != 0:
         logging(
         logging(
             code="4006",
             code="4006",
             info="抖音请求详情失败",
             info="抖音请求详情失败",
-            data={"error": str(e)}
+            data={"error": response['msg']}
         )
         )
-        return None
+    else:
+        try:
+            video_info = response['data']['data']
+            if video_info['content_type'] == "note":
+                return None
+            else:
+                return video_info
+        except Exception as e:
+            logging(
+                code="4006",
+                info="抖音请求详情失败",
+                data={"error": str(e)}
+            )
+            return None