Parcourir la source

调整设备搜索接口频繁异常问题

yf_fyh il y a 3 ans
Parent
commit
01bb6b8d88
1 fichiers modifiés avec 22 ajouts et 8 suppressions
  1. 22 8
      utils/utils.py

+ 22 - 8
utils/utils.py

@@ -13,16 +13,30 @@ def get_equip_list(d_id, isfullId=0):
     :return:列表数据,相同设备号放一起,并且最近更新数据靠前,最近更新数据可认为设备最后所在平台
     """
     if isfullId == 1:
-        bigdata_res = requests.post("http://8.136.98.49:8002/search/equip", data={"device_id": d_id, "isfullId": "1"},
-                                    timeout=5)
-        siqing_res = requests.post("http://www.yfzhwlw.com/search/equip", data={"device_id": d_id, "isfullId": "1"},
-                                   timeout=5)
+        try:
+            bigdata_res = requests.post("http://8.136.98.49:8002/search/equip", data={"device_id": d_id, "isfullId": "1"},timeout=10)
+            bigdata_dict = json.loads(bigdata_res.content.decode())
+        except:
+            bigdata_dict = {}
+        try:
+            siqing_res = requests.post("http://www.yfzhwlw.com/search/equip", data={"device_id": d_id, "isfullId": "1"},timeout=10)
+            siqing_dict = json.loads(siqing_res.content.decode())
+        except:
+            siqing_dict = {}
     else:
-        bigdata_res = requests.post("http://8.136.98.49:8002/search/equip", data={"device_id": d_id}, timeout=5)
-        siqing_res = requests.post("http://www.yfzhwlw.com/search/equip", data={"device_id": d_id}, timeout=5)
+        try:
+            bigdata_res = requests.post("http://8.136.98.49:8002/search/equip", data={"device_id": d_id}, timeout=10)
+            bigdata_dict = json.loads(bigdata_res.content.decode())
+        except:
+            bigdata_dict = {}
+        try:
+            siqing_res = requests.post("http://www.yfzhwlw.com/search/equip", data={"device_id": d_id}, timeout=10)
+            siqing_dict = json.loads(siqing_res.content.decode())
+        except:
+            siqing_dict = {}
 
-    django_data = json.loads(bigdata_res.content.decode()).get("data", [])
-    siqing_data = json.loads(siqing_res.content.decode()).get("data", [])
+    django_data = bigdata_dict.get("data", [])
+    siqing_data = siqing_dict.get("data", [])
     data = []
     data.extend(django_data)
     data.extend(siqing_data)