|
@@ -17,12 +17,14 @@ except ImportError:
|
|
|
try:
|
|
|
from instagram_private_api import (
|
|
|
Client, ClientError, ClientLoginError,
|
|
|
- ClientCookieExpiredError, ClientLoginRequiredError)
|
|
|
+ ClientCookieExpiredError,
|
|
|
+ ClientTwoFactorRequiredError)
|
|
|
except ImportError:
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
from instagram_private_api import (
|
|
|
Client, ClientError, ClientLoginError,
|
|
|
- ClientCookieExpiredError, ClientLoginRequiredError)
|
|
|
+ ClientCookieExpiredError,
|
|
|
+ ClientTwoFactorRequiredError)
|
|
|
|
|
|
|
|
|
def to_json(python_object):
|
|
@@ -65,6 +67,21 @@ def authenticate(username, password, force_use_login_args=False):
|
|
|
ig_api = Client(
|
|
|
username, password,
|
|
|
on_login=lambda x: onlogin_callback(x, cookie_file), proxy=pil.proxy)
|
|
|
+ try:
|
|
|
+ ig_api.login()
|
|
|
+ except ClientTwoFactorRequiredError as e:
|
|
|
+ response = json.loads(e.error_response)
|
|
|
+ two_factor_info = response['two_factor_info']
|
|
|
+ two_factor_identifier = two_factor_info['two_factor_identifier']
|
|
|
+ if two_factor_info['totp_two_factor_on']:
|
|
|
+ code_device = 'one-time password app'
|
|
|
+ else:
|
|
|
+ code_device = 'number ending with {}'.format(two_factor_info['obfuscated_phone_number'])
|
|
|
+ verification_code = input('Enter verification code, sent to {}: '.format(code_device))
|
|
|
+ try:
|
|
|
+ ig_api.login2fa(two_factor_identifier, verification_code)
|
|
|
+ except ClientError as e:
|
|
|
+ print(e.error_response)
|
|
|
else:
|
|
|
with open(cookie_file) as file_data:
|
|
|
cached_settings = json.load(file_data, object_hook=from_json)
|