summaryrefslogtreecommitdiffstats
path: root/fb.py
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-07-06 08:41:42 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-07-06 08:41:42 +0200
commit11f4d323d88e06c632ff29923d50a77deeb85e34 (patch)
tree1c1e790bad47a2de53e95ff913ae2bb08265a546 /fb.py
parent61284c48b7f014d234dee0b98a0bc439e8f51d56 (diff)
Retry on login error when creating API key
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'fb.py')
-rwxr-xr-xfb.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/fb.py b/fb.py
index 48b34f4..85dd375 100755
--- a/fb.py
+++ b/fb.py
@@ -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: