From 5b910871285ba58d97f3164a87e3cfa8d4d28d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 13 Jul 2024 17:25:32 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/requests.py | 6 +++--- LunaTranslator/LunaTranslator/translator/youdao.py | 7 ++----- LunaTranslator/LunaTranslator/translator/youdao5.py | 8 ++++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/LunaTranslator/LunaTranslator/requests.py b/LunaTranslator/LunaTranslator/requests.py index c7823ca5..4ba1b2d8 100644 --- a/LunaTranslator/LunaTranslator/requests.py +++ b/LunaTranslator/LunaTranslator/requests.py @@ -322,7 +322,7 @@ class Session: from network.winhttp.requester import Requester self._requester = Requester() self._libidx = globalconfig["network"] - + self.headers.update({"Accept-Encoding": self.requester.Accept_Encoding}) self.headers.update({"User-Agent": self.requester.default_UA}) return self._requester @@ -346,13 +346,13 @@ class Session: verify=False, cert=None, ): - + requester = self.requester if cookies: self.cookies.update(cookies) _h = self.headers.copy() if headers: _h.update(headers) - response = self.requester.request( + response = requester.request( method.upper(), url, params, diff --git a/LunaTranslator/LunaTranslator/translator/youdao.py b/LunaTranslator/LunaTranslator/translator/youdao.py index c833576d..56d5c360 100644 --- a/LunaTranslator/LunaTranslator/translator/youdao.py +++ b/LunaTranslator/LunaTranslator/translator/youdao.py @@ -4,7 +4,6 @@ from translator.basetranslator import basetrans import random - class TS(basetrans): def langmap(self): return {"zh": "zh-CHS"} @@ -27,7 +26,7 @@ class TS(basetrans): } def inittranslator(self): - self.headers = { + headers = { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6", "Cache-Control": "no-cache", @@ -45,9 +44,7 @@ class TS(basetrans): } # proxies = { "http": None, "https": None} - self.proxysession.trust_env = False - self.proxysession.headers.update(self.headers) - self.proxysession.get("https://fanyi.youdao.com") + self.proxysession.get("https://fanyi.youdao.com", headers=headers) def translate(self, content): diff --git a/LunaTranslator/LunaTranslator/translator/youdao5.py b/LunaTranslator/LunaTranslator/translator/youdao5.py index d2d6db07..950739ee 100644 --- a/LunaTranslator/LunaTranslator/translator/youdao5.py +++ b/LunaTranslator/LunaTranslator/translator/youdao5.py @@ -6,7 +6,7 @@ class TS(basetrans): return {"zh": "zh-CHS"} def inittranslator(self): - self.headers = { + headers = { "authority": "ai.youdao.com", "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-language": "zh-CN,zh;q=0.9", @@ -22,9 +22,9 @@ class TS(basetrans): "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36", } - self.proxysession.trust_env = False - self.proxysession.headers.update(self.headers) - self.proxysession.get("https://ai.youdao.com/product-fanyi-text.s") + self.proxysession.get( + "https://ai.youdao.com/product-fanyi-text.s", headers=headers + ) def translate(self, content):