claude.ai has the same Cloudflare TLS fingerprinting protection as chatgpt.com. Apply the same fix: curl_cffi impersonate=chrome120, remove base class User-Agent to avoid JA3/UA mismatch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
23 lines
755 B
Python
23 lines
755 B
Python
"""Debug script — tests Claude API connectivity using curl_cffi Chrome impersonation."""
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from curl_cffi import requests as curl_requests
|
|
|
|
load_dotenv()
|
|
key = os.getenv("CLAUDE_SESSION_KEY")
|
|
if not key:
|
|
print("ERROR: CLAUDE_SESSION_KEY not found in .env")
|
|
raise SystemExit(1)
|
|
|
|
s = curl_requests.Session(impersonate="chrome120")
|
|
s.cookies.set("sessionKey", key, domain="claude.ai", path="/")
|
|
s.headers.update({
|
|
"Referer": "https://claude.ai/",
|
|
"Accept": "application/json",
|
|
})
|
|
|
|
print("Calling /api/organizations (with Chrome TLS impersonation) ...")
|
|
r = s.get("https://claude.ai/api/organizations", timeout=15)
|
|
print(f"Status: {r.status_code}")
|
|
print(f"Response (first 400 chars): {r.text[:400]}")
|