From ba75e2786e13c4ad4e5a941516b1c4a727197b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Ho=CC=88nicke?= Date: Sat, 22 Apr 2023 22:34:15 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9B=85=20fix:=20executor=20push=20on=20windo?= =?UTF-8?q?ws?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/jina_cloud.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/apis/jina_cloud.py b/src/apis/jina_cloud.py index 41e2475..5d5de62 100644 --- a/src/apis/jina_cloud.py +++ b/src/apis/jina_cloud.py @@ -7,15 +7,15 @@ import threading import time import webbrowser from pathlib import Path +from typing import Dict import click import hubble import requests -from hubble.executor.helper import upload_file, archive_package, get_request_header +from hubble.executor.helper import upload_file, archive_package, get_full_version from jcloud.flow import CloudFlow from jina import Flow -from src.apis.gpt import configure_openai_api_key from src.constants import DEMO_TOKEN from src.utils.io import suppress_stdout, is_docker_running from src.utils.string_tools import print_colored @@ -71,6 +71,21 @@ def push_executor(dir_path): print(f'connection error - retrying in 5 seconds...') time.sleep(5) +def get_request_header() -> Dict: + """Return the header of request with an authorization token. + + :return: request header + """ + metas, envs = get_full_version() + + headers = { + **{f'jinameta-{k}': str(v) for k, v in metas.items()}, + **envs, + } + headers['Authorization'] = f'token {DEMO_TOKEN}' + + return headers + def _push_executor(dir_path): dir_path = Path(dir_path) md5_hash = hashlib.md5() @@ -88,7 +103,6 @@ def _push_executor(dir_path): } with suppress_stdout(): headers = get_request_header() - headers['Authorization'] = f'token {DEMO_TOKEN}' resp = upload_file( 'https://api.hubble.jina.ai/v2/rpc/executor.push',