debug_50001.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. """Properly read the 50001 error and trace the real flow.
  2. Three things to do:
  3. 1. Force UTF-8 output so we can read the actual error message
  4. 2. Wait for geetest to fully load (with screenshot to confirm)
  5. 3. After solving, capture the captcha and send it WITH the form
  6. """
  7. import asyncio
  8. import base64
  9. import json
  10. import os
  11. import sys
  12. from pathlib import Path
  13. # Force UTF-8 console output
  14. sys.stdout.reconfigure(encoding="utf-8", errors="replace")
  15. sys.stderr.reconfigure(encoding="utf-8", errors="replace")
  16. _HERE = Path(__file__).resolve().parent
  17. sys.path.insert(0, str(_HERE.parent / "src"))
  18. from cq2_sdk.env_loader import load_env
  19. load_env(_HERE.parent / ".env")
  20. from cq2_sdk.login.jfbym import JfbymSliderSolver
  21. from cq2_sdk.login.box_996 import Box996Login
  22. from cq2_sdk.store import UserStore, connection
  23. EDGE = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
  24. URL = "https://pc.hzwlan.com/login/account"
  25. async def main():
  26. from playwright.async_api import async_playwright
  27. async with async_playwright() as p:
  28. browser = await p.chromium.launch(executable_path=EDGE, headless=True)
  29. ctx = await browser.new_context(viewport={"width": 1366, "height": 768})
  30. page = await ctx.new_page()
  31. # 1. Open page, fill form via React-friendly native setter
  32. await page.goto(URL, wait_until="networkidle", timeout=30000)
  33. await page.evaluate(
  34. "([u, p]) => {"
  35. " const setVal = (sel, v) => {"
  36. " const el = document.querySelector(sel);"
  37. " Object.getOwnPropertyDescriptor("
  38. " window.HTMLInputElement.prototype, 'value').set.call(el, v);"
  39. " el.dispatchEvent(new Event('input', {bubbles: true}));"
  40. " };"
  41. " setVal('input#username', u);"
  42. " setVal('input#password', p);"
  43. "}",
  44. ["longwu988", "Longwu1988"],
  45. )
  46. # 2. Wait for geetest widget to fully load
  47. print("[step 2] waiting for geetest widget...")
  48. try:
  49. await page.wait_for_selector(
  50. ".geetest_widget, .geetest_captcha, [class*=geetest]",
  51. timeout=10000,
  52. )
  53. print(" -> geetest widget present")
  54. except Exception as e:
  55. print(f" -> no geetest widget after 10s: {e}")
  56. print(f" -> page text: {(await page.locator('body').inner_text())[:200]}")
  57. # 3. Screenshot pre-submit state
  58. out = _HERE / "jfbym_diag"
  59. await page.screenshot(path=str(out / "a1_pre_submit.png"), full_page=True)
  60. print(f" -> screenshot: {out / 'a1_pre_submit.png'}")
  61. # 4. Detect captcha widget type and structure
  62. info = await page.evaluate("""() => {
  63. return {
  64. geetest_els: [...document.querySelectorAll('[class*=geetest]')].map(e => ({
  65. tag: e.tagName, cls: e.className.slice(0, 60)
  66. })),
  67. canvas_count: document.querySelectorAll('canvas').length,
  68. canvas_classes: [...document.querySelectorAll('canvas')].map(c => c.className),
  69. yidun_els: [...document.querySelectorAll('[class*=yidun],[class*=netease]')].map(e => ({
  70. tag: e.tagName, cls: e.className.slice(0, 60)
  71. })),
  72. iframe_count: document.querySelectorAll('iframe').length,
  73. iframe_srcs: [...document.querySelectorAll('iframe')].map(i => i.src.slice(0, 100)),
  74. };
  75. }""")
  76. print(f" -> geetest els: {info['geetest_els']}")
  77. print(f" -> canvases: {info['canvas_count']} {info['canvas_classes']}")
  78. print(f" -> yidun els: {info['yidun_els']}")
  79. print(f" -> iframes ({info['iframe_count']}): {info['iframe_srcs']}")
  80. # 5. Click submit, capture the response
  81. print("\n[step 5] clicking submit, capturing byPwd response...")
  82. async with page.expect_response("**/auth/v3/login/safe/byPwd") as resp_info:
  83. await page.locator("button.login-form_box__submit_button").first.click(force=True)
  84. response = await resp_info.value
  85. status = response.status
  86. body = await response.text()
  87. await browser.close()
  88. print(f"\n=== byPwd response ===")
  89. print(f"status: {status}")
  90. print(f"body: {body}")
  91. try:
  92. data = json.loads(body)
  93. print(f"parsed: code={data.get('code')}, msg={data.get('msg')!r}, data={data.get('data')}")
  94. except Exception:
  95. pass
  96. asyncio.run(main())