Skip to content

Commit e014b1f

Browse files
committed
Fix second factor auth
1 parent e7dce49 commit e014b1f

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

vk_api/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ def send(self, request, **kwargs):
143143

144144
total = end - start
145145

146+
body = request.body
147+
if body and len(body) > 1024:
148+
body = body[:1024] + '[STRIPPED]'
149+
146150
print(
147-
'{:0.2f} {} {} {} {}'.format(
151+
'{:0.2f} {} {} {} {} {}'.format(
148152
total,
149153
request.method,
150154
request.url,
155+
repr(body),
151156
response.status_code,
152157
response.history
153158
)

vk_api/vk_api.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
RE_LOGIN_HASH = re.compile(r'name="lg_h" value="([a-z0-9]+)"')
2828
RE_CAPTCHAID = re.compile(r"onLoginCaptcha\('(\d+)'")
2929
RE_NUMBER_HASH = re.compile(r"al_page: '3', hash: '([a-z0-9]+)'")
30-
RE_AUTH_HASH = re.compile(
31-
r"\{.*?act: 'a_authcheck_code'.+?hash: '([a-z_0-9]+)'.*?\}"
32-
)
30+
RE_AUTH_HASH = re.compile(r"Authcheck\.init\('([a-z_0-9]+)'")
3331
RE_TOKEN_URL = re.compile(r'location\.href = "(.*?)"\+addr;')
3432

3533
RE_PHONE_PREFIX = re.compile(r'label ta_r">\+(.*?)<')
@@ -317,19 +315,28 @@ def _pass_twofactor(self, auth_response):
317315
318316
:param auth_response: страница с приглашением к аутентификации
319317
"""
320-
code, remember_device = self.error_handlers[TWOFACTOR_CODE]()
321318

322319
auth_hash = search_re(RE_AUTH_HASH, auth_response.text)
323320

321+
if not auth_hash:
322+
raise TwoFactorError(
323+
'Two factor authentication can not be passed:'
324+
' could not find "hash" value. Please create a bugreport'
325+
)
326+
327+
code, remember_device = self.error_handlers[TWOFACTOR_CODE]()
328+
324329
values = {
325-
'act': 'a_authcheck_code',
326330
'al': '1',
327331
'code': code,
328-
'remember': int(remember_device),
329332
'hash': auth_hash,
333+
'remember': int(remember_device),
330334
}
331335

332-
response = self.http.post('https://vk.com/al_login.php', values)
336+
response = self.http.post(
337+
'https://vk.com/al_login.php?act=a_authcheck_code',
338+
values
339+
)
333340
data = json.loads(response.text.lstrip('<!--'))
334341
status = data['payload'][0]
335342

0 commit comments

Comments
 (0)