"""最小复现：QuecPython request.post 带请求体时报
ValueError: InvalidSchema: No connection adapters were found for '...'。

设备端运行（只用固件自带模块，不依赖任何项目代码）：
    import example; example.exec('/usr/repro_post_body.py')

复现要点：同一个 URL、同一套 headers：
  - POST 空 body   -> 正常（404）
  - POST 带 body   -> 抛 ValueError: InvalidSchema ...
  - GET            -> 正常（200）
  - POST 带 body 到百度 -> 正常（404/200），说明 body 本身没问题
"""

URL = "https://hewc-api-ssl.mynatapp.cc/"
BODY = '{"deviceId":"860000000000000"}'
HEADERS = {"Content-Type": "application/json"}
TIMEOUT = 10

print("=" * 56)
try:
    import uos
    print("[SYS]", uos.uname())
except Exception:
    pass

import request


def show(name, fn):
    try:
        resp = fn()
        code = getattr(resp, "status_code", "?")
        print("[OK]   {0} -> status={1}".format(name, code))
        try:
            resp.close()
        except Exception:
            pass
        return True
    except Exception as exc:
        print("[FAIL] {0} -> {1}: {2}".format(name, type(exc).__name__, exc))
        try:
            import sys
            sys.print_exception(exc)
        except Exception:
            pass
        return False


print("-" * 56)
print("case 1: POST + body        (reproduces the failure)")
show("POST body", lambda: request.post(URL, data=BODY, headers=HEADERS, timeout=TIMEOUT))

print("-" * 56)
print("case 2: POST + empty body  (works)")
show("POST empty body", lambda: request.post(URL, data="", headers=HEADERS, timeout=TIMEOUT))

print("-" * 56)
print("case 3: GET                (works)")
show("GET", lambda: request.get(URL, timeout=TIMEOUT))

print("-" * 56)
print("case 4: POST + body to baidu (works; rules out body content)")
show("POST baidu", lambda: request.post(
    "https://www.baidu.com/robots.txt", data=BODY, headers=HEADERS, timeout=TIMEOUT))

print("=" * 56)
print("[DONE] case1 FAIL + case2/3/4 OK => request.post body-sending defect")
