debug_login3.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Debug: Capture exact login request and response.
  3. """
  4. from playwright.sync_api import sync_playwright
  5. BASE_URL = "http://localhost:80"
  6. with sync_playwright() as p:
  7. browser = p.chromium.launch(headless=True)
  8. page = browser.new_page(viewport={"width": 1440, "height": 900})
  9. api_responses = []
  10. def on_response(response):
  11. if "/auth/login" in response.url or "/system/" in response.url:
  12. try:
  13. body = response.text()
  14. api_responses.append({
  15. "url": response.url,
  16. "status": response.status,
  17. "body": body[:500],
  18. })
  19. except:
  20. api_responses.append({
  21. "url": response.url,
  22. "status": response.status,
  23. "body": "<error reading body>",
  24. })
  25. page.on("response", on_response)
  26. page.goto(f"{BASE_URL}/login", wait_until="networkidle", timeout=30000)
  27. page.wait_for_timeout(1000)
  28. page.locator('input[placeholder="用户名"]').fill("admin")
  29. page.locator('input[placeholder="密码"]').fill("admin123")
  30. page.locator('button:has-text("登")').click()
  31. page.wait_for_timeout(8000)
  32. print(f"URL: {page.url}")
  33. print(f"\nAPI responses ({len(api_responses)}):")
  34. for r in api_responses:
  35. print(f"\n {r['url']}")
  36. print(f" Status: {r['status']}")
  37. print(f" Body: {r['body'][:300]}")
  38. browser.close()