diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-07-06 08:41:42 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2016-07-06 08:41:42 +0200 |
commit | 11f4d323d88e06c632ff29923d50a77deeb85e34 (patch) | |
tree | 1c1e790bad47a2de53e95ff913ae2bb08265a546 /fb.py | |
parent | 61284c48b7f014d234dee0b98a0bc439e8f51d56 (diff) |
Retry on login error when creating API key
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'fb.py')
-rwxr-xr-x | fb.py | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -775,12 +775,24 @@ class FBClient: localuser = getpass.getuser() data = [] - data.append({'username': self.get_input("Username: ")}) - data.append({'password': self.get_input("Password: ", display=False)}) - data.append({'comment': "fb-client %s@%s" % (localuser, hostname)}) - data.append({'access_level': "apikey"}) + while True: + data.append({'username': self.get_input("Username: ")}) + data.append({'password': self.get_input("Password: ", display=False)}) + data.append({'comment': "fb-client %s@%s" % (localuser, hostname)}) + data.append({'access_level': "apikey"}) + + try: + resp = self.curlw.send_post_noauth('/user/create_apikey', data) + # break out of while loop on success + break + except APIException as e: + if e.error_id == 'user/login-failed': + eprint(e) + eprint("\nPlease try again:") + continue + else: + raise - resp = self.curlw.send_post_noauth('/user/create_apikey', data) self.makedirs(os.path.dirname(self.config['apikey_file'])) with open(self.config['apikey_file'], 'w') as outfile: |