Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use another rundb url tk_rundb_api_url to generate token #135

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading