Skip to content

Commit

Permalink
fix: bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
txperl committed Oct 30, 2024
1 parent 6e25863 commit 9fc4349
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
30 changes: 15 additions & 15 deletions app/lib/common/login_helper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CommonLoginHelper(interRoot):
def __init__(self):
self.lang = self.INS.i18n.get_bundle("app.common.loginHelper", func=True)
self.requests = requests.Session()
self.requests.mount("https://", CustomAdapter())
# self.requests.mount("https://", CustomAdapter())
self.token_getter = TokenGetter(lang=self.lang, requests=self.requests)
self.proxy = ""
self.auth_token_url = ""
Expand Down Expand Up @@ -152,19 +152,19 @@ def _get(cls, url, proxy="", silent=False):
return True


class CustomAdapter(requests.adapters.HTTPAdapter):
"""
防止在请求 Cloudflare 时可能的 SSL 相关错误。
Thanks to @github/grawity.
"""
# class CustomAdapter(requests.adapters.HTTPAdapter):
# """
# 防止在请求 Cloudflare 时可能的 SSL 相关错误。
# Thanks to @github/grawity.
# """

def init_poolmanager(self, *args, **kwargs):
# When urllib3 hand-rolls a SSLContext, it sets 'options |= OP_NO_TICKET'
# and CloudFlare really does not like this. We cannot control this behavior
# in urllib3, but we can just pass our own standard context instead.
import ssl
# def init_poolmanager(self, *args, **kwargs):
# # When urllib3 hand-rolls a SSLContext, it sets 'options |= OP_NO_TICKET'
# # and CloudFlare really does not like this. We cannot control this behavior
# # in urllib3, but we can just pass our own standard context instead.
# import ssl

ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ctx.load_default_certs()
ctx.set_alpn_protocols(["http/1.1"])
return super().init_poolmanager(*args, **kwargs, ssl_context=ctx)
# ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
# ctx.load_default_certs()
# ctx.set_alpn_protocols(["http/1.1"])
# return super().init_poolmanager(*args, **kwargs, ssl_context=ctx)
7 changes: 3 additions & 4 deletions app/lib/core/biu.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __pre_check(self):
self.STATIC.localMsger.red(self.lang("config.hint_port_is_in_use"))
input(self.lang("common.press_to_exit"))
sys.exit(0)
# 检测 cache 大小
# 检测 Cache 大小
cache_path = self.getENV("rootPath") + "usr/cache/search/"
size_cache = self.STATIC.file.get_dir_size_mib(cache_path)
if size_cache > float(self.sets["biu"]["search"]["maxCacheSizeMiB"]):
Expand Down Expand Up @@ -125,14 +125,13 @@ def __check_out_network(self):
self.STATIC.localMsger.msg(self.lang("network.hint_in_check"))
try:
if self.proxy != "":
requests.get("https://pixiv.net/", proxies={"https": self.proxy}, timeout=3)
requests.head("https://pixiv.net/", proxies={"https": self.proxy}, timeout=3)
else:
requests.get("https://pixiv.net/", timeout=3)
requests.head("https://pixiv.net/", timeout=3)
except:
self.STATIC.localMsger.red(self.lang("network.fail_pixiv_and_use_bypass"))
self.api_route = "bypassSNI"
self.proxy = ""
time.sleep(5)

def __login(self, refresh_token=None, silent=False):
"""
Expand Down
12 changes: 6 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
from altfe.interface.root import classRoot

# Fix SSL socket connection issues in some systems
import ssl
# import ssl

create_default_context_orig = ssl.create_default_context
# create_default_context_orig = ssl.create_default_context


def cdc(*args, **kwargs):
kwargs["purpose"] = ssl.Purpose.SERVER_AUTH
return create_default_context_orig(*args[1:], **kwargs)
# def cdc(*args, **kwargs):
# kwargs["purpose"] = ssl.Purpose.SERVER_AUTH
# return create_default_context_orig(*args[1:], **kwargs)


ssl.create_default_context = cdc
# ssl.create_default_context = cdc
# Fix End

rootPath = os.path.split(os.path.realpath(sys.argv[0]))[0] + "/"
Expand Down

0 comments on commit 9fc4349

Please sign in to comment.