#!/usr/bin/env python3 """ Debug redirect on AI playground page. """ import re import httpx BASE_URL = "http://localhost:8000" def main(): print("Debugging redirect on AI playground page...") with httpx.Client(base_url=BASE_URL, timeout=30.0) as client: # Login first response = client.get("/admin/login") match = re.search(r'name="csrf_token" value="([^"]+)"', response.text) csrf_token = match.group(1) if match else "" response = client.post( "/admin/login", data={ "username": "admin", "password": "admin123", "csrf_token": csrf_token, }, follow_redirects=True, ) print(f"Logged in, URL: {response.url}") # Get AI playground page without following redirects print("\nGetting AI playground page without following redirects...") response = client.get( "/admin/questions/1/generate?tab=review", follow_redirects=False ) print(f"Status: {response.status_code}") print(f"Location header: {response.headers.get('location', 'None')}") # Follow the redirect if response.headers.get("location"): redirect_url = response.headers["location"] print(f"\nFollowing redirect to: {redirect_url}") response = client.get(redirect_url, follow_redirects=True) print(f"Final status: {response.status_code}") print(f"Final URL: {response.url}") # Check for forms post_forms = re.findall( r'