From b8fe8bbc1d9db88e964c3070c55d06e9c5723e19 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:18:00 +0800 Subject: [PATCH] fix --- LunaTranslator/LunaTranslator/requests.py | 30 +++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/LunaTranslator/LunaTranslator/requests.py b/LunaTranslator/LunaTranslator/requests.py index 8fa1f6cb..ec269bb6 100644 --- a/LunaTranslator/LunaTranslator/requests.py +++ b/LunaTranslator/LunaTranslator/requests.py @@ -124,15 +124,6 @@ class Requester_common: Accept_Encoding = "gzip, deflate, br" default_UA = default_UA - default_headers = CaseInsensitiveDict( - { - "User-Agent": default_UA, - # "Accept-Encoding": "gzip, deflate, br", - "Accept": "*/*", - "Connection": "keep-alive", - } - ) - @staticmethod def _encode_params(data): if isinstance(data, (str, bytes)): @@ -226,12 +217,6 @@ class Requester_common: cert=None, ) -> ResponseBase: - _h = self.default_headers.copy() - _h.update({"Accept-Encoding": self.Accept_Encoding}) - if headers: - _h.update(headers) - headers = _h - if auth and isinstance(auth, tuple) and len(auth) == 2: headers["Authorization"] = ( "Basic " @@ -313,6 +298,14 @@ class Session: _requester = None _libidx = -1 + headers = CaseInsensitiveDict( + { + # "Accept-Encoding": "gzip, deflate, br", + "Accept": "*/*", + "Connection": "keep-alive", + } + ) + def __enter__(self): return self @@ -353,12 +346,17 @@ class Session: if cookies: self.cookies.update(cookies) + _h = self.headers.copy() + _h.update({"Accept-Encoding": self.requester.Accept_Encoding}) + _h.update({"User-Agent": self.requester.default_UA}) + if headers: + _h.update(headers) response = self.requester.request( method.upper(), url, params, data, - headers, + _h, proxies, json, self.cookies,