Bläddra i källkod

更新oss配置和客户端错误输出描述

dongzhaorui 1 dag sedan
förälder
incheckning
d5adc21d99

+ 2 - 2
FworkSpider/feapder/utils/oss.py

@@ -134,14 +134,14 @@ class JyOssClient:
             "stream": stream
         }
 
-        ret = {"error_msg": "附件上传错误", "error_code": -1}
+        ret = {"error_msg": "附件上传失败", "error_code": -1}
         for _ in range(retries):
             ret = self._oss_client.upload(args)
             if ret["error_code"] == 0:
                 return ret
 
         if err_show:
-            raise AttachmentError(reason=ret.get("error_msg") or "附件上传错误")
+            raise AttachmentError(reason=ret.get("error_msg") or "附件上传失败")
 
         return ret
 

+ 1 - 1
FworkSpider/setting.py

@@ -109,7 +109,7 @@ ITEM_FILTER_SETTING = dict(
         },
         "lua": {
             "fingerprint_pref": "list_",
-            "ip_port": "172.17.4.84:4679",
+            "ip_port": "172.20.16.214:4679",
             "user_pass": "jytopnet123",
             "db": 0
         }

+ 4 - 7
FworkSpider/untils/attachment.py

@@ -16,7 +16,7 @@ import urllib3
 
 import feapder.utils.tools as tools
 from feapder.utils.log import log as logger
-from feapder.utils.oss import JyOssClient, OssBucketClient
+from feapder.utils.oss import JyOssClient
 
 urllib3.disable_warnings()
 
@@ -37,8 +37,7 @@ class Downloader:
 
     def __init__(self):
         self.dir_name = "file"
-        # self._oss = JyOssClient()
-        self._bucket = OssBucketClient()
+        self._oss = JyOssClient()
 
     def create_file(self, filename, filetype):
         os.makedirs(self.dir_name, mode=0o777, exist_ok=True)
@@ -228,8 +227,7 @@ class Downloader:
                 attachment["fid"] = "{}.{}".format(fid, filetype)
                 attachment["size"] = self.getsize(stream)
                 attachment["url"] = "oss"
-                # self._oss.upload("file", attachment["fid"], stream, gzip=gzip)
-                self._bucket.put_object(attachment["fid"], stream)
+                self._oss.upload("file", attachment["fid"], stream, gzip=gzip)
             except Exception as e:
                 logger.error(
                     "[{}]上传失败,原因:{}".format(filename, e.__class__.__name__)
@@ -266,8 +264,7 @@ class Downloader:
                 attachment["size"] = self.getsize(file)
                 attachment["ftype"] = filetype
                 attachment["url"] = "oss"
-                # self._oss.upload("file", attachment["fid"], stream, gzip=gzip)
-                self._bucket.put_object_from_file(attachment["fid"], file)
+                self._oss.upload("file", attachment["fid"], stream, gzip=gzip)
             except Exception as e:
                 logger.error(
                     "[{}]上传失败,原因:{}".format(filename, e.__class__.__name__)

+ 6 - 8
FworkSpider/untils/attachment_res.py

@@ -16,7 +16,7 @@ import urllib3
 
 import feapder.utils.tools as tools
 from feapder.utils.log import log as logger
-from feapder.utils.oss import JyOssClient, OssBucketClient
+from feapder.utils.oss import JyOssClient
 
 urllib3.disable_warnings()
 # 文件文档类型
@@ -156,17 +156,16 @@ def judge_file_url(file_url: str):
 class Downloader:
 
     def __init__(self):
-        self.dir_name = "file"
-        # self._oss = JyOssClient()
-        self._bucket = OssBucketClient()
+        self._directory = "file"
+        self._oss = JyOssClient()
 
     def _create_file(self, filename, filetype):
-        os.makedirs(self.dir_name, mode=0o777, exist_ok=True)
+        os.makedirs(self._directory, mode=0o777, exist_ok=True)
         file = "{filename}.{filetype}".format(
             filename=tools.get_sha1("{}_{}".format(filename, uuid.uuid4())),
             filetype=filetype
         )
-        return "{}/{}".format(self.dir_name, file)
+        return "{}/{}".format(self._directory, file)
 
     @staticmethod
     def _file_size(file: str):
@@ -263,8 +262,7 @@ class Downloader:
                 attachment["size"] = self._file_size(local_temp_file)
                 attachment["ftype"] = filetype
                 attachment["url"] = "oss"
-                # self._oss.upload("file", attachment["fid"], filestream)
-                self._bucket.put_object_from_file(attachment["fid"], local_temp_file)
+                self._oss.upload("file", attachment["fid"], filestream)
             except Exception as e:
                 logger.error(
                     "[{}]上传失败,原因:{}".format(file_name, e.__class__.__name__)