diff --git a/PicImageSearch/saucenao.py b/PicImageSearch/saucenao.py index 23562e18..51b6c0d1 100644 --- a/PicImageSearch/saucenao.py +++ b/PicImageSearch/saucenao.py @@ -115,6 +115,7 @@ def __init__(self, dbmask: int = None, dbmaski: int = None, db: int = 999, + **requests_kwargs ) -> None: """ :param api_key:(str)用于SauceNAO的访问密钥 (默认=None) @@ -128,6 +129,7 @@ def __init__(self, :param hide:(int)结果隐藏控制,无=0,明确返回值(默认)=1,怀疑返回值=2,全部返回值=3 """ # minsim 控制最小相似度 + self.requests_kwargs = requests_kwargs params = dict() if api_key is not None: params['api_key'] = api_key @@ -155,7 +157,7 @@ def search(self, url: str, files=None): image.save(imageData, format='PNG') files = {'file': ("image.png", imageData.getvalue())} imageData.close() - resp = requests.post(self.SauceNAOURL, params=params, files=files) + resp = requests.post(self.SauceNAOURL, params=params, files=files,**self.requests_kwargs) status_code = resp.status_code logger.info(status_code) data = resp.json() diff --git a/test/test2.py b/test/test2.py index 97624399..1bbc9eb7 100644 --- a/test/test2.py +++ b/test/test2.py @@ -4,14 +4,21 @@ from PicImageSearch.saucenao import SauceNAO -saucenao = SauceNAO(api_key='54a8d90c583d3b66b6dd3d7e9001a39b588cd842',testmode=1) +_REQUESTS_KWARGS = { + 'proxies': { + 'https': 'http://127.0.0.1:10809', + } + # 如果需要代理 +} +saucenao = SauceNAO(api_key='54a8d90c583d3b66b6dd3d7e9001a39b588cd842', testmode=1, **_REQUESTS_KWARGS) res = saucenao.search('https://cdn.jsdelivr.net/gh/laosepi/setu/pics_original/77702503_p0.jpg') logger.info(res.origin) # 原始数据 logger.info(res.raw) # logger.info(res.raw[0]) # logger.info(res.long_remaining) # 99 logger.info(res.short_remaining) # 3 -logger.info(res.raw[0].thumbnail) # https://img1.saucenao.com/res/pixiv/7770/77702503_p0_master1200.jpg?auth=pJmiu8qNI1z2fLBAlAsx7A&exp=1604748473 +logger.info(res.raw[ + 0].thumbnail) # https://img1.saucenao.com/res/pixiv/7770/77702503_p0_master1200.jpg?auth=pJmiu8qNI1z2fLBAlAsx7A&exp=1604748473 logger.info(res.raw[0].similarity) # 92.22 logger.info(res.raw[0].title) # MDR♡ logger.info(res.raw[0].author) # CeNanGam diff --git a/wiki/SauceNAO.md b/wiki/SauceNAO.md index d16d81f9..9f5387fe 100644 --- a/wiki/SauceNAO.md +++ b/wiki/SauceNAO.md @@ -3,7 +3,13 @@ ``` from loguru import logger from PicImageSeach.saucenao import SauceNAO -saucenao = SauceNAO() +_REQUESTS_KWARGS = { + # 'proxies': { + # 'https': 'http://127.0.0.1:10809', + # } + #如果需要代理 +} +saucenao = SauceNAO(**_REQUESTS_KWARGS) res = saucenao.search('https://cdn.jsdelivr.net/gh/laosepi/setu/pics_original/77702503_p0.jpg') #res = saucenao.search(r'C:/kitUIN/img/tinted-good.jpg')搜索本地图片 logger.info(res.origin) # 原始数据