#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""取证：CDN 域名下的 /api/... 到底返回什么（为何 JSON 解析报 '<'）。"""
import ssl
import urllib.error
import urllib.request

CDN = 'https://bier-sales-d0gatbvlx288724e9-1458438710.tcloudbaseapp.com'
TUNNEL = 'https://api.biorisales.site:8443'
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

for base, tag in [(CDN, 'CDN'), (TUNNEL, '隧道')]:
    for p in ['/api/visit/stats?month=2026-10', '/api/todos']:
        try:
            r = urllib.request.urlopen(urllib.request.Request(base + p, headers={'User-Agent': 'probe'}),
                                       timeout=20, context=ctx)
            body = r.read()[:120].decode('utf-8', 'ignore')
            print('%-4s HTTP %s  %-30s  Content-Type=%s' % (tag, r.status, p, r.headers.get('Content-Type')))
            print('       前 120 字符: %s' % body.replace('\n', ' '))
        except urllib.error.HTTPError as e:
            body = e.read()[:120].decode('utf-8', 'ignore')
            print('%-4s HTTP %s  %-30s  Content-Type=%s' % (tag, e.code, p, e.headers.get('Content-Type')))
            print('       前 120 字符: %s' % body.replace('\n', ' '))
        except Exception as e:
            print('%-4s 失败 %-30s %s' % (tag, p, str(e)[:70]))
