瀏覽代碼

保存回调带上请求头

莺声燕语 2 年之前
父節點
當前提交
6b2cf8ee5b
共有 3 個文件被更改,包括 36 次插入7 次删除
  1. 1 1
      utils/html_again_parse.py
  2. 21 6
      utils/ruku_opera.py
  3. 14 0
      utils/ruku_test.py

+ 1 - 1
utils/html_again_parse.py

@@ -173,7 +173,7 @@ def css_label_wash(content):
             # a.append(str(html)) # 会自动带上</?p> ;&变为&amp;
             a.append(content.strip())
 
-        new_a = "\n".join(list(filter(lambda x: x.strip(), a)))
+        new_a = "\n".join(list(map(lambda x: x.strip(), a)))
         if subs2img:
             new_a = re.sub("|".join(subs2img.keys()), lambda x: subs2img[x.group()], new_a)
         # new_a = "<p>" + new_a.replace("\n\n", "\n").replace("\n", "</p>\n<p>") + "</p>"

+ 21 - 6
utils/ruku_opera.py

@@ -377,6 +377,11 @@ class Ruku():
                     # 查重
                     if self.source != "xue_guan":
                         repeat_r, repeat_time = self.repeat_check(nn, one_items, repeat_time)
+                        if type(repeat_r) == str:
+                            res_xbk = {"items": [], "errcode": 1, "errmsg": repeat_r, "callback_type": 2}
+                            res_zyk = {"errcode": 1, "errmsgs": repeat_r, "data": {}}
+                            self.callback_user(res_xbk, self.callback_url)
+                            return res_zyk
                         new_one_item["repeat_res"] = repeat_r
                     new_one_item["topic_type_id"] = one_items["checkType"]["id"]
                     if "options_rank" in one_items and one_items["options_rank"]:
@@ -430,6 +435,11 @@ class Ruku():
                     # 查重
                     if self.source != "xue_guan":
                         repeat_r, repeat_time = self.repeat_check(nn, one_items, repeat_time)
+                        if type(repeat_r) == str:
+                            res_xbk = {"items": [], "errcode": 1, "errmsg": repeat_r, "callback_type": 2}
+                            res_zyk = {"errcode": 1, "errmsgs": repeat_r, "data": {}}
+                            self.callback_user(res_xbk, self.callback_url)
+                            return res_zyk
                         new_one_item["repeat_res"] = repeat_r
                     new_one_item["topic_type_id"] = one_items["checkType"]["id"]
                     if "options_rank" in one_items and one_items["options_rank"]:
@@ -619,12 +629,16 @@ class Ruku():
             chachong_item_dict["options"] = one_items["options"]
         if "slave" in one_items:
             chachong_item_dict["slave"] = one_items["slave"]
-        repeat_r = requests.post(url=configs.repeat_ip, json=[chachong_item_dict]).json()
-        print("查重结果:", repeat_r)  # [str(id + 1)]
-        if repeat_r:
-            repeat_r = repeat_r[str(id + 1)]
-        else:
-            repeat_r = []
+        try:
+            repeat_r = requests.post(url=configs.repeat_ip, json=[chachong_item_dict]).json()
+            print("查重结果:", repeat_r)  # [str(id + 1)]
+            if repeat_r:
+                repeat_r = repeat_r[str(id + 1)]
+            else:
+                repeat_r = []
+        except Exception as e:
+            logger.info("----【paper_id:{}】查重服务异常:{}".format(self.wordid, e))
+            repeat_r = "保存入库查重服务异常"
         repeat_time += time.time() - t22
         return repeat_r, repeat_time
 
@@ -647,6 +661,7 @@ class Ruku():
         try:
             r = requests.post(callback_url,
                               # json=res, # 可以,但是会进行转义
+                              headers={"Content-Type": "application/json"},
                               data=json.dumps(res_xbk, ensure_ascii=False).encode("utf-8"),  # 文件开头有编码显示
                               )
             print("------【paper_id:{}】,post 回调地址状态:{}===>回调结果: {} -------\n".format(self.wordid, r.status_code, r.text))

+ 14 - 0
utils/ruku_test.py

@@ -0,0 +1,14 @@
+
+import pickle
+from utils.ruku_opera import Ruku
+
+
+f1 = open(r"C:\Users\Python\Desktop\test\44\struct_items.pickle",'rb').read()
+items_list = pickle.loads(f1)
+# pprint(items_list)
+f2 = open(r"C:\Users\Python\Desktop\test\44\svg_data.pickle", 'rb').read()
+svg_data = pickle.loads(f2)
+# print(svg_data["svg_html_data"])
+res = Ruku(items_list, "", svg_data, "0213441313131", {"callback_url": "1223", "source": "teacher"}, "高中地理").upload_img()
+# a,t = Ruku("","","","").get_phy_kps_auto(one_item, 0)
+print(res)