This commit is contained in:
恍兮惚兮 2024-07-13 17:25:32 +08:00
parent 099fb4764d
commit 5b91087128
3 changed files with 9 additions and 12 deletions

View File

@ -322,7 +322,7 @@ class Session:
from network.winhttp.requester import Requester from network.winhttp.requester import Requester
self._requester = Requester() self._requester = Requester()
self._libidx = globalconfig["network"] self._libidx = globalconfig["network"]
self.headers.update({"Accept-Encoding": self.requester.Accept_Encoding}) self.headers.update({"Accept-Encoding": self.requester.Accept_Encoding})
self.headers.update({"User-Agent": self.requester.default_UA}) self.headers.update({"User-Agent": self.requester.default_UA})
return self._requester return self._requester
@ -346,13 +346,13 @@ class Session:
verify=False, verify=False,
cert=None, cert=None,
): ):
requester = self.requester
if cookies: if cookies:
self.cookies.update(cookies) self.cookies.update(cookies)
_h = self.headers.copy() _h = self.headers.copy()
if headers: if headers:
_h.update(headers) _h.update(headers)
response = self.requester.request( response = requester.request(
method.upper(), method.upper(),
url, url,
params, params,

View File

@ -4,7 +4,6 @@ from translator.basetranslator import basetrans
import random import random
class TS(basetrans): class TS(basetrans):
def langmap(self): def langmap(self):
return {"zh": "zh-CHS"} return {"zh": "zh-CHS"}
@ -27,7 +26,7 @@ class TS(basetrans):
} }
def inittranslator(self): 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": "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", "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", "Cache-Control": "no-cache",
@ -45,9 +44,7 @@ class TS(basetrans):
} }
# proxies = { "http": None, "https": None} # proxies = { "http": None, "https": None}
self.proxysession.trust_env = False self.proxysession.get("https://fanyi.youdao.com", headers=headers)
self.proxysession.headers.update(self.headers)
self.proxysession.get("https://fanyi.youdao.com")
def translate(self, content): def translate(self, content):

View File

@ -6,7 +6,7 @@ class TS(basetrans):
return {"zh": "zh-CHS"} return {"zh": "zh-CHS"}
def inittranslator(self): def inittranslator(self):
self.headers = { headers = {
"authority": "ai.youdao.com", "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": "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", "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", "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.get(
self.proxysession.headers.update(self.headers) "https://ai.youdao.com/product-fanyi-text.s", headers=headers
self.proxysession.get("https://ai.youdao.com/product-fanyi-text.s") )
def translate(self, content): def translate(self, content):