Skip to content

Commit 8581b46

Browse files
authored
examples - two factor authentication
1 parent 1ae51de commit 8581b46

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

examples/auth_handler

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
import vk_api
3+
4+
5+
def auth_handler():
6+
""" При возникновении двухфакторной аутентификации вызывается эта функция.
7+
"""
8+
9+
# Код двухфакторной аутентификации
10+
key = input("Enter authentication code: ")
11+
# Если 1 то сохранить, 0 не сохранять.
12+
remember_device = 1
13+
14+
# Отправляет запрос
15+
return key, remember_device
16+
17+
18+
def main():
19+
""" Пример обработки двухфакторной аутентификации """
20+
21+
login, password = 'python@vk.com', 'mypassword'
22+
vk_session = vk_api.VkApi(
23+
login, password,
24+
auth_handler=auth_handler # функция для обработки двухфакторной аутентификации
25+
)
26+
27+
try:
28+
vk_session.auth()
29+
except vk_api.AuthError as error_msg:
30+
print(error_msg)
31+
return
32+
33+
# ...
34+
35+
if __name__ == '__main__':
36+
main()

0 commit comments

Comments
 (0)