diff --git a/pleroma.py b/pleroma.py index 306dd61..261c47b 100644 --- a/pleroma.py +++ b/pleroma.py @@ -86,14 +86,19 @@ class Account(): response = self.apiRequest('POST', '/oauth/token', request_data) if 'error' in response and response['error'] == 'mfa_required': if response['supported_challenge_types'] == 'totp' or 'totp' in response['supported_challenge_types']: - mfa_code, code_type = self.totpFunc(self, response['supported_challenge_types']) - response = self.apiRequest('POST', '/oauth/mfa/challenge', { - 'client_id': self.clientID, - 'client_secret': self.clientSecret, - 'mfa_token': response['mfa_token'], - 'challenge_type': code_type, - 'code': mfa_code - }) + ctypes = response['supported_challenge_types'] + mfa_token = response['mfa_token'] + while True: + mfa_code, code_type = self.totpFunc(self, ctypes) + response = self.apiRequest('POST', '/oauth/mfa/challenge', { + 'client_id': self.clientID, + 'client_secret': self.clientSecret, + 'mfa_token': mfa_token, + 'challenge_type': code_type, + 'code': mfa_code + }) + if not 'error' in response: + break elif 'error' in response: raise ValueError self.token = response['access_token']