MCPcopy
hub / github.com/InstaPy/InstaPy / login_user

Function login_user

instapy/login_util.py:231–548  ·  view source on GitHub ↗

Logins the user with the given username and password

(
    browser,
    username,
    password,
    logger,
    logfolder,
    proxy_address,
    security_code_to_phone,
    security_codes,
    want_check_browser,
)

Source from the content-addressed store, hash-verified

229
230
231def login_user(
232 browser,
233 username,
234 password,
235 logger,
236 logfolder,
237 proxy_address,
238 security_code_to_phone,
239 security_codes,
240 want_check_browser,
241):
242 """Logins the user with the given username and password"""
243 assert username, "Username not provided"
244 assert password, "Password not provided"
245
246 # Hotfix - this check crashes more often than not -- plus in not necessary,
247 # I can verify my own connection
248 if want_check_browser:
249 if not check_browser(browser, logfolder, logger, proxy_address):
250 return False
251
252 ig_homepage = "https://www.instagram.com"
253 web_address_navigator(browser, ig_homepage)
254
255 cookie_file = "{0}{1}_cookie.pkl".format(logfolder, username)
256 cookie_loaded = None
257 login_state = None
258
259 # try to load cookie from username
260 try:
261 for cookie in pickle.load(open(cookie_file, "rb")):
262 # SameSite = Strict, your cookie will only be sent in a
263 # first-party context. In user terms, the cookie will only be sent
264 # if the site for the cookie matches the site currently shown in
265 # the browser's URL bar.
266 if "sameSite" in cookie and cookie["sameSite"] == "None":
267 cookie["sameSite"] = "Strict"
268
269 browser.add_cookie(cookie)
270
271 sleep(4)
272 cookie_loaded = True
273 logger.info("- Cookie file for user '{}' loaded...".format(username))
274
275 # force refresh after cookie load or check_authorization() will FAIL
276 reload_webpage(browser)
277 sleep(4)
278
279 # cookie has been LOADED, so the user SHOULD be logged in
280 login_state = check_authorization(
281 browser, username, "activity counts", logger, False
282 )
283 sleep(4)
284
285 except (WebDriverException, OSError, IOError):
286 # Just info the user, not an error
287 logger.info("- Cookie file not found, creating cookie...")
288

Callers 1

loginMethod · 0.85

Calls 14

check_browserFunction · 0.85
web_address_navigatorFunction · 0.85
sleepFunction · 0.85
reload_webpageFunction · 0.85
check_authorizationFunction · 0.85
dismiss_save_informationFunction · 0.85
accept_igcookie_dialogueFunction · 0.85
read_xpathFunction · 0.85
update_activityFunction · 0.85
explicit_waitFunction · 0.85

Tested by

no test coverage detected