From 78217432b644bb9f86e2c4d2a9c6949dffeec18b Mon Sep 17 00:00:00 2001 From: smolkik-code Date: Wed, 17 Jun 2026 11:40:27 +0700 Subject: [PATCH] fix: better diagnostics for cookie auth failures - Detect missing sessionid cookie and log clear error - Improved instructions for both auth methods --- instagram_monitor.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/instagram_monitor.py b/instagram_monitor.py index f5a8662..8985345 100644 --- a/instagram_monitor.py +++ b/instagram_monitor.py @@ -58,7 +58,21 @@ class InstagramMonitor: logger.info("Session loaded from cookies.txt") return True except Exception as e: - logger.warning(f"cookies.txt invalid: {e}") + logger.warning(f"cookies.txt invalid or missing sessionid cookie: {e}") + # Check what cookies are actually in the file + try: + import http.cookiejar + cj = http.cookiejar.MozillaCookieJar(str(cookies_path)) + cj.load(ignore_discard=True, ignore_expires=True) + cookie_names = [c.name for c in cj] + logger.info(f"Cookies found in file: {cookie_names}") + if "sessionid" not in cookie_names: + logger.error( + "cookies.txt is missing 'sessionid' cookie. " + "You must be logged into instagram.com in the browser before exporting." + ) + except Exception: + pass # Method 3: load cookies.json exported from browser extension cookies_json_path = Path(config.download_dir) / "cookies.json" @@ -80,9 +94,10 @@ class InstagramMonitor: except Exception as e: logger.error(f"Direct login failed: {e}") logger.info( - "Use cookies.txt or cookies.json instead. " - "Export from browser: install 'Get cookies.txt LOCALLY' extension, " - "go to instagram.com, export, put file in /data/downloads/cookies.txt" + "Instagram blocks most automated logins. " + "Use one of these methods instead:\n" + " 1. Run 'instaloader --login=USERNAME' on host, copy session to data/\n" + " 2. Export cookies from browser (must have sessionid cookie)" ) return False