From 58b5ec421148c43b5a27ced8b571d2deb9c9b313 Mon Sep 17 00:00:00 2001 From: ricterzheng Date: Tue, 28 Jan 2025 17:43:50 +0800 Subject: [PATCH] fix #382 --- nhentai/cmdline.py | 5 +---- nhentai/command.py | 4 ++-- nhentai/constant.py | 2 +- nhentai/utils.py | 7 +++++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 1f7e096..fd74c3d 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -189,10 +189,7 @@ def cmd_parser(): logger.error(f'Invalid protocol "{proxy_url.scheme}" of proxy, ignored') sys.exit(0) else: - constant.CONFIG['proxy'] = { - 'http': args.proxy, - 'https': args.proxy, - } + constant.CONFIG['proxy'] = args.proxy logger.info(f'Proxy now set to "{args.proxy}"') write_config() sys.exit(0) diff --git a/nhentai/command.py b/nhentai/command.py index 6b8a119..55dc1e6 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -28,8 +28,8 @@ def main(): logger.info(f'Using mirror: {BASE_URL}') # CONFIG['proxy'] will be changed after cmd_parser() - if constant.CONFIG['proxy']['http']: - logger.info(f'Using proxy: {constant.CONFIG["proxy"]["http"]}') + if constant.CONFIG['proxy']: + logger.info(f'Using proxy: {constant.CONFIG["proxy"]}') if not constant.CONFIG['template']: constant.CONFIG['template'] = 'default' diff --git a/nhentai/constant.py b/nhentai/constant.py index 7af8bde..b27c4fd 100644 --- a/nhentai/constant.py +++ b/nhentai/constant.py @@ -55,7 +55,7 @@ NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json') __api_suspended_DETAIL_URL = f'{BASE_URL}/api/gallery' CONFIG = { - 'proxy': {'http': '', 'https': ''}, + 'proxy': '', 'cookie': '', 'language': '', 'template': '', diff --git a/nhentai/utils.py b/nhentai/utils.py index 445ec27..c73e78d 100644 --- a/nhentai/utils.py +++ b/nhentai/utils.py @@ -31,7 +31,10 @@ def request(method, url, **kwargs): }) if not kwargs.get('proxies', None): - kwargs['proxies'] = constant.CONFIG['proxy'] + kwargs['proxies'] = { + 'https': constant.CONFIG['proxy'], + 'http': constant.CONFIG['proxy'], + } return getattr(session, method)(url, verify=False, **kwargs) @@ -46,7 +49,7 @@ async def async_request(method, url, proxy = None, **kwargs): if proxy is None: proxy = constant.CONFIG['proxy'] - if proxy is not None and proxy.get('http') == '' and proxy.get('https') == '': + if isinstance(proxy, (str, )) and not proxy: proxy = None async with httpx.AsyncClient(headers=headers, verify=False, proxy=proxy, **kwargs) as client: