Skip to content

Commit bf711df

Browse files
committed
Fix VkApi._pass_twofactor
1 parent 404d83e commit bf711df

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

vk_api/vk_api.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:copyright: (c) 2019 python273
77
"""
88

9+
import json
910
import logging
1011
import random
1112
import re
@@ -329,14 +330,19 @@ def _pass_twofactor(self, auth_response):
329330
}
330331

331332
response = self.http.post('https://vk.com/al_login.php', values)
332-
response_parsed = response.text.split('<!>')
333+
data = json.loads(response.text.lstrip('<!--'))
334+
status = data['payload'][0]
333335

334-
if response_parsed[4] == '4': # OK
335-
return self.http.get('https://vk.com/' + response_parsed[5])
336+
if status == '4': # OK
337+
path = json.loads(data['payload'][1][0])
338+
return self.http.get('https://vk.com' + path)
336339

337-
elif response_parsed[4] == '8': # Incorrect code
340+
elif status in [0, '8']: # Incorrect code
338341
return self._pass_twofactor(auth_response)
339342

343+
elif status == '2':
344+
raise TwoFactorError('Recaptcha required')
345+
340346
raise TwoFactorError('Two factor authentication failed')
341347

342348
def _pass_security_check(self, response=None):

0 commit comments

Comments
 (0)