From 4800d415ae18a293b22fd00cbf9c1eb16cf5a35a 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: Sun, 18 Aug 2024 17:00:53 +0800 Subject: [PATCH] issues/1008 https://github.com/HIllya51/LunaTranslator/issues/1008 --- .../network/winhttp/requester.py | 6 +++- LunaTranslator/LunaTranslator/requests.py | 28 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/LunaTranslator/LunaTranslator/network/winhttp/requester.py b/LunaTranslator/LunaTranslator/network/winhttp/requester.py index 8906d556..7d57afa0 100644 --- a/LunaTranslator/LunaTranslator/network/winhttp/requester.py +++ b/LunaTranslator/LunaTranslator/network/winhttp/requester.py @@ -13,7 +13,6 @@ except: print_exc() - class Response(ResponseBase): def iter_content_impl(self, chunk_size=1): availableSize = DWORD() @@ -48,6 +47,11 @@ class Response(ResponseBase): class Requester(Requester_common): + def request(self, *argc, **kwarg) -> ResponseBase: + if kwarg["stream"]: + # winhttp流式时,没办法判断解压边界 + kwarg["headers"].pop("Accept-Encoding") + return super().request(*argc, **kwarg) def _getheaders(self, hreq): dwSize = DWORD() diff --git a/LunaTranslator/LunaTranslator/requests.py b/LunaTranslator/LunaTranslator/requests.py index 5049ee18..ab43d066 100644 --- a/LunaTranslator/LunaTranslator/requests.py +++ b/LunaTranslator/LunaTranslator/requests.py @@ -413,20 +413,20 @@ class Session: response = requester.request( method.upper(), url, - params, - data, - _h, - proxies, - json, - self.cookies, - files, - auth, - timeout, - allow_redirects, - hooks, - stream, - verify, - cert, + params=params, + data=data, + headers=_h, + proxies=proxies, + json=json, + cookies=self.cookies, + files=files, + auth=auth, + timeout=timeout, + allow_redirects=allow_redirects, + hooks=hooks, + stream=stream, + verify=verify, + cert=cert, ) self.cookies.update(response.cookies) response.cookies.update(self.cookies)