MCPcopy
hub / github.com/InstaPy/InstaPy / login

Method login

instapy/instapy.py:422–480  ·  view source on GitHub ↗

Used to login the user either with the username and password

(self)

Source from the content-addressed store, hash-verified

420 return self
421
422 def login(self):
423 """Used to login the user either with the username and password"""
424 # InstaPy uses page_delay speed to implicit wait for elements,
425 # here we're decreasing it to 5 seconds instead of the default 25
426 # seconds to speed up the login process.
427 #
428 # In short: default page_delay speed took 25 seconds trying to locate
429 # every element, now it's taking 5 seconds.
430 temporary_page_delay = 5
431 self.browser.implicitly_wait(temporary_page_delay)
432
433 if not login_user(
434 self.browser,
435 self.username,
436 self.password,
437 self.logger,
438 self.logfolder,
439 self.proxy_address,
440 self.bypass_security_challenge_using,
441 self.security_codes,
442 self.want_check_browser,
443 ):
444 message = (
445 "Unable to login to Instagram! "
446 "You will find more information in the logs above."
447 )
448 highlight_print(self.username, message, "login", "critical", self.logger)
449
450 self.aborting = True
451 return self
452
453 # back the page_delay to default, or the value set by the user
454 self.browser.implicitly_wait(self.page_delay)
455 message = "Logged in successfully!"
456 highlight_print(self.username, message, "login", "info", self.logger)
457 # try to save account progress
458 try:
459 save_account_progress(self.browser, self.username, self.logger)
460 except Exception as e:
461 # Comment:
462 # Saw this error:
463 # "TypeError: window._sharedData.entry_data.ProfilePage is undefined"
464 # when IG deleted a pic or video due community guidelines, then the
465 # FF session shows a different page that interrupts the normal flow.
466 self.logger.warning(
467 "Unable to save account progress, skipping data update \n\t{}".format(
468 str(e).encode("utf-8")
469 )
470 )
471
472 # logs only followers/following numbers when able to login,
473 # to speed up the login process and avoid loading profile
474 # page (meaning less server calls)
475 self.followed_by = log_follower_num(self.browser, self.username, self.logfolder)
476 self.following_num = log_following_num(
477 self.browser, self.username, self.logfolder
478 )
479

Callers 1

smart_runFunction · 0.80

Calls 5

login_userFunction · 0.85
highlight_printFunction · 0.85
save_account_progressFunction · 0.85
log_follower_numFunction · 0.85
log_following_numFunction · 0.85

Tested by

no test coverage detected