Skip to content

Commit

Permalink
Use another rundb url tk_rundb_api_url to generate token
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Oct 4, 2024
1 parent f3150f3 commit 83024c9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions utilix/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, path):
raise RuntimeError(
f"Cannot open {path}, "
"please report to https://github.com/XENONnT/utilix/issues. "
f'To continue do "rm {path}" and restart notebook/utilix.'
f"To continue do 'rm {path}' and restart notebook/utilix."
) from e
self.token_string = json_in["string"]
self.creation_time = json_in["creation_time"]
Expand Down Expand Up @@ -102,7 +102,11 @@ def __call__(self):
return self.token_string

def new_token(self):
path = PREFIX + "/login"
tk_rundb_api_url = uconfig.get("RunDB", "tk_rundb_api_url", fallback=None)
if tk_rundb_api_url:
paths = [tk_rundb_api_url + "/login", PREFIX + "/login"]
else:
paths = [PREFIX + "/login"]
username = uconfig.get("RunDB", "rundb_api_user")
pw = uconfig.get("RunDB", "rundb_api_password")
data = json.dumps({"username": username, "password": pw})
Expand All @@ -112,10 +116,13 @@ def new_token(self):
success = False
for _try in range(n_try):
try:
response = requests.post(path, data=data, headers=BASE_HEADERS)
response_json = json.loads(response.text)
success = True
break
for path in paths:
response = requests.post(path, data=data, headers=BASE_HEADERS)
response_json = json.loads(response.text)
success = True
break
if success:
break
except json.decoder.JSONDecodeError:
logger.info(
f"Login attempt #{_try+1} failed. "
Expand Down

0 comments on commit 83024c9

Please sign in to comment.