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