Files
ai-chatexport/debug_auth.py
2026-02-28 05:24:18 -05:00

38 lines
1.3 KiB
Python

"""Debug script — checks what /api/auth/session returns using curl_cffi Chrome impersonation."""
import os
from dotenv import load_dotenv
from curl_cffi import requests as curl_requests
load_dotenv()
token = os.getenv("CHATGPT_SESSION_TOKEN")
if not token:
print("ERROR: CHATGPT_SESSION_TOKEN not found in .env")
raise SystemExit(1)
s = curl_requests.Session(impersonate="chrome120")
s.cookies.set("__Secure-next-auth.session-token", token, domain="chatgpt.com", path="/")
s.headers.update({
"Referer": "https://chatgpt.com/",
"Accept": "*/*",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
})
print("Calling /api/auth/session (with Chrome TLS impersonation) ...")
r = s.get("https://chatgpt.com/api/auth/session", timeout=15)
print(f"Status: {r.status_code}")
print(f"Content-Type: {r.headers.get('content-type', '(none)')}")
try:
data = r.json()
print(f"Top-level keys: {list(data.keys())}")
access_token = data.get("accessToken")
if access_token:
print(f"accessToken: FOUND (length={len(access_token)}, starts with '{access_token[:10]}...')")
else:
print("accessToken: NOT FOUND in response")
print(f"Full response body:\n{r.text}")
except Exception as e:
print(f"Could not parse JSON: {e}\nRaw body:\n{r.text[:500]}")