From 8581b460c81b7b32e5d41b6057d27327e6f438fb Mon Sep 17 00:00:00 2001 From: user Date: Tue, 4 Apr 2017 14:50:04 +0300 Subject: [PATCH 1/4] examples - two factor authentication --- examples/auth_handler | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/auth_handler diff --git a/examples/auth_handler b/examples/auth_handler new file mode 100644 index 00000000..233d7d95 --- /dev/null +++ b/examples/auth_handler @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import vk_api + + +def auth_handler(): + """ При возникновении двухфакторной аутентификации вызывается эта функция. + """ + + # Код двухфакторной аутентификации + key = input("Enter authentication code: ") + # Если 1 то сохранить, 0 не сохранять. + remember_device = 1 + + # Отправляет запрос + return key, remember_device + + +def main(): + """ Пример обработки двухфакторной аутентификации """ + + login, password = 'python@vk.com', 'mypassword' + vk_session = vk_api.VkApi( + login, password, + auth_handler=auth_handler # функция для обработки двухфакторной аутентификации + ) + + try: + vk_session.auth() + except vk_api.AuthError as error_msg: + print(error_msg) + return + + # ... + +if __name__ == '__main__': + main() From e3fd94bc2c5f60479cf2237159db76e02931a532 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 4 Apr 2017 14:50:47 +0300 Subject: [PATCH 2/4] fix --- examples/{auth_handler => auth_handler.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{auth_handler => auth_handler.py} (100%) diff --git a/examples/auth_handler b/examples/auth_handler.py similarity index 100% rename from examples/auth_handler rename to examples/auth_handler.py From 87ba52fdf12a2bad53befb991631f153c9bbcfcd Mon Sep 17 00:00:00 2001 From: user Date: Tue, 4 Apr 2017 20:07:33 +0300 Subject: [PATCH 3/4] corrected comments and file name --- examples/{auth_handler.py => two_factor_auth.py} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename examples/{auth_handler.py => two_factor_auth.py} (75%) diff --git a/examples/auth_handler.py b/examples/two_factor_auth.py similarity index 75% rename from examples/auth_handler.py rename to examples/two_factor_auth.py index 233d7d95..5c588bbd 100644 --- a/examples/auth_handler.py +++ b/examples/two_factor_auth.py @@ -3,15 +3,14 @@ def auth_handler(): - """ При возникновении двухфакторной аутентификации вызывается эта функция. + """ При двухфакторной аутентификации вызывается эта функция. """ # Код двухфакторной аутентификации key = input("Enter authentication code: ") - # Если 1 то сохранить, 0 не сохранять. + # Если: 1 - сохранить, 0 - не сохранять. remember_device = 1 - # Отправляет запрос return key, remember_device From 7bf67f61bf5d1a5c710104495c74c97c4c1e3e11 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 4 Apr 2017 20:13:51 +0300 Subject: [PATCH 4/4] translated int to boolean --- examples/two_factor_auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/two_factor_auth.py b/examples/two_factor_auth.py index 5c588bbd..3e75a531 100644 --- a/examples/two_factor_auth.py +++ b/examples/two_factor_auth.py @@ -8,8 +8,8 @@ def auth_handler(): # Код двухфакторной аутентификации key = input("Enter authentication code: ") - # Если: 1 - сохранить, 0 - не сохранять. - remember_device = 1 + # Если: True - сохранить, False - не сохранять. + remember_device = True return key, remember_device