fix: better diagnostics for cookie auth failures
- Detect missing sessionid cookie and log clear error - Improved instructions for both auth methods
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user