Allow on_2fa_callback to be None in Session.login
This commit is contained in:
@@ -2663,26 +2663,6 @@ class Client:
|
||||
EVENTS
|
||||
"""
|
||||
|
||||
def on_logging_in(self, email=None):
|
||||
"""Called when the client is logging in.
|
||||
|
||||
Args:
|
||||
email: The email of the client
|
||||
"""
|
||||
log.info("Logging in {}...".format(email))
|
||||
|
||||
def on_2fa_code(self):
|
||||
"""Called when a 2FA code is needed to progress."""
|
||||
return input("Please enter your 2FA code --> ")
|
||||
|
||||
def on_logged_in(self, email=None):
|
||||
"""Called when the client is successfully logged in.
|
||||
|
||||
Args:
|
||||
email: The email of the client
|
||||
"""
|
||||
log.info("Login of {} successful.".format(email))
|
||||
|
||||
def on_listening(self):
|
||||
"""Called when the client is listening."""
|
||||
log.info("Listening...")
|
||||
|
@@ -132,13 +132,14 @@ class Session:
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def login(cls, email, password, on_2fa_callback):
|
||||
def login(cls, email, password, on_2fa_callback=None):
|
||||
"""Login the user, using ``email`` and ``password``.
|
||||
|
||||
Args:
|
||||
email: Facebook ``email`` or ``id`` or ``phone number``
|
||||
password: Facebook account password
|
||||
on_2fa_callback: Function that will be called, in case a 2FA code is needed
|
||||
on_2fa_callback: Function that will be called, in case a 2FA code is needed.
|
||||
This should return the requested 2FA code.
|
||||
|
||||
Raises:
|
||||
FBchatException: On failed login
|
||||
@@ -159,6 +160,10 @@ class Session:
|
||||
|
||||
# Usually, 'Checkpoint' will refer to 2FA
|
||||
if "checkpoint" in r.url and ('id="approvals_code"' in r.text.lower()):
|
||||
if not on_2fa_callback:
|
||||
raise _exception.FBchatException(
|
||||
"2FA code required, please add `on_2fa_callback` to .login"
|
||||
)
|
||||
code = on_2fa_callback()
|
||||
r = _2fa_helper(session, code, r)
|
||||
|
||||
|
Reference in New Issue
Block a user