Make cookie-file auth env-only for multi-account use
All checks were successful
CI / test (3.11) (push) Successful in 55s
CI / test (3.10) (push) Successful in 1m58s
CI / test (3.12) (push) Successful in 1m0s

This commit is contained in:
2026-05-08 16:47:34 +02:00
parent bc82333e07
commit 4878d11b15
4 changed files with 8 additions and 18 deletions

View File

@@ -2,7 +2,7 @@
Supports:
1. Environment variables: TWITTER_AUTH_TOKEN + TWITTER_CT0
2. Cookie file: TWITTER_COOKIE_FILE or config auth.cookieFile (Netscape cookies.txt)
2. Cookie file: TWITTER_COOKIE_FILE (Netscape cookies.txt)
3. Auto-extract from browser via browser-cookie3
Extracts ALL Twitter cookies for full browser-like fingerprint.
Prefers in-process extraction (required on macOS for Keychain access),
@@ -664,10 +664,7 @@ def get_cookies(config: Optional[Dict[str, Any]] = None) -> Dict[str, str]:
# 2. Try cookie file from env/config
if not cookies:
auth_config = (config or {}).get("auth", {})
cookie_file = os.environ.get("TWITTER_COOKIE_FILE", "")
if not cookie_file and isinstance(auth_config, dict):
cookie_file = str(auth_config.get("cookieFile", "") or "")
cookies = load_from_cookie_file(cookie_file)
if cookies:
logger.info("Loaded cookies from cookie file %s", cookie_file)
@@ -687,7 +684,7 @@ def get_cookies(config: Optional[Dict[str, Any]] = None) -> Dict[str, str]:
lines.extend(" " + line for line in hint.splitlines())
lines.append("")
lines.append("Option 1: Set TWITTER_AUTH_TOKEN and TWITTER_CT0 environment variables")
lines.append("Option 2: Set TWITTER_COOKIE_FILE or config auth.cookieFile to a Netscape cookies.txt export")
lines.append("Option 2: Set TWITTER_COOKIE_FILE to a Netscape cookies.txt export")
lines.append("Option 3: Make sure you are logged into x.com in your browser (Arc/Chrome/Edge/Firefox/Brave)")
lines.append("")
lines.append("Run 'twitter -v <command>' for debug diagnostics.")