Add try/except to get_key method
This commit is contained in:
parent
476fe8e671
commit
7747ea7d9f
25
main.py
25
main.py
@ -21,7 +21,6 @@ class Access(object):
|
||||
if platform == 'dci':
|
||||
self.user_table = AuthUser
|
||||
self.platform = platform
|
||||
self.input_container = 'input'
|
||||
|
||||
def get_admin(self):
|
||||
"""
|
||||
@ -66,13 +65,28 @@ class Access(object):
|
||||
Returns:
|
||||
_dict_: _access key_
|
||||
"""
|
||||
host = self.input_container
|
||||
host = 'input'
|
||||
if self.platform == 'dci':
|
||||
host = 'dci_input_1' # because this hostname
|
||||
|
||||
url = 'http://{}:1500/api/auth/v4/user/{}/key'.format(
|
||||
host, admin['id']
|
||||
)
|
||||
headers = {"Internal-Auth": "on", "Accept": "application/json"}
|
||||
|
||||
check_key = 0
|
||||
|
||||
while check_key != 3:
|
||||
try:
|
||||
req = requests.post(url, headers=headers, data={})
|
||||
key = req.json()
|
||||
answer = req.json()
|
||||
key = answer['key']
|
||||
print("Key will be used:")
|
||||
print(key, "\n")
|
||||
break
|
||||
except Exception:
|
||||
check_key += 1
|
||||
key = 'not_found_try_again'
|
||||
return key
|
||||
|
||||
|
||||
@ -92,10 +106,7 @@ def main():
|
||||
|
||||
key = access.get_key(account)
|
||||
|
||||
print("Key will be used:")
|
||||
print(key, "\n")
|
||||
|
||||
access_link = 'https://{}/auth/key-v4/{}'.format(CLIENT_HOST, key['key'])
|
||||
access_link = 'https://{}/auth/key-v4/{}'.format(CLIENT_HOST, key)
|
||||
|
||||
print("Your access link: \n")
|
||||
print(access_link, "\n")
|
||||
|
Loading…
Reference in New Issue
Block a user