From a3384225137d880689baeb35f1b69af8ec64a603 Mon Sep 17 00:00:00 2001 From: Zhaofeng Miao <522856232@qq.com> Date: Thu, 19 May 2022 14:23:36 +0800 Subject: [PATCH 1/2] feat(hubble): use fixed domain for hubble api Avoid several problems caused by unstable api.jina.ai --- jina/hubble/helper.py | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/jina/hubble/helper.py b/jina/hubble/helper.py index 1f80ca721437c..87d86427017cb 100644 --- a/jina/hubble/helper.py +++ b/jina/hubble/helper.py @@ -94,27 +94,14 @@ def get_download_cache_dir() -> Path: @lru_cache() def _get_hubble_base_url() -> str: - """Get base Hubble Url from api.jina.ai or os.environ + """Get base Hubble Url from os.environ or constants :return: base Hubble Url """ if 'JINA_HUBBLE_REGISTRY' in os.environ: - u = os.environ['JINA_HUBBLE_REGISTRY'] - else: - try: - req = Request( - 'https://api.jina.ai/hub/hubble.json', - headers={'User-Agent': 'Mozilla/5.0'}, - ) - with urlopen(req) as resp: - u = json.load(resp)['url'] - except: - default_logger.critical( - 'Can not fetch the Url of Hubble from `api.jina.ai`' - ) - raise - - return u + return os.environ['JINA_HUBBLE_REGISTRY'] + + return 'https://api.hubble.jina.ai' @lru_cache() From 8d4ee80cebed8f76751181e20b3f70bb73689334 Mon Sep 17 00:00:00 2001 From: Zhaofeng Miao <522856232@qq.com> Date: Thu, 19 May 2022 16:37:57 +0800 Subject: [PATCH 2/2] fix: optimize the syntax --- jina/hubble/helper.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jina/hubble/helper.py b/jina/hubble/helper.py index 87d86427017cb..783392c4217d5 100644 --- a/jina/hubble/helper.py +++ b/jina/hubble/helper.py @@ -98,10 +98,7 @@ def _get_hubble_base_url() -> str: :return: base Hubble Url """ - if 'JINA_HUBBLE_REGISTRY' in os.environ: - return os.environ['JINA_HUBBLE_REGISTRY'] - - return 'https://api.hubble.jina.ai' + return os.environ.get('JINA_HUBBLE_REGISTRY', 'https://api.hubble.jina.ai') @lru_cache()