Smail/test/tools/test_email_list.py
smail 9813c9cd0f
Some checks are pending
Security Checks / security (push) Waiting to run
test: 增加刷新按钮与定时轮询机制云端部署端到端验收脚本
2026-09-14 09:28:25 +08:00

19 lines
1.1 KiB
Python

import urllib.request, ssl, json, http.cookiejar
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPSHandler(context=ctx), urllib.request.HTTPCookieProcessor(cj))
login_payload = json.dumps({"account": "xuans", "password": "12345678"}).encode("utf-8")
req = urllib.request.Request("https://47.108.78.12/api/v1/login", data=login_payload, headers={"Content-Type": "application/json"})
resp = opener.open(req, timeout=5)
login_res = json.loads(resp.read().decode("utf-8"))
csrf_token = ""
for cookie in cj:
if cookie.name == "smail_csrf":
csrf_token = cookie.value
headers = {"Content-Type": "application/json", "X-CSRF-Token": csrf_token}
# 正常前端请求 list 携带的参数
req_email = urllib.request.Request("https://47.108.78.12/api/v1/email/list", data=json.dumps({"tag": "{\"type\":0,\"status\":-1}", "page_size": 15}).encode("utf-8"), headers=headers)
resp_email = opener.open(req_email, timeout=5)
print("Email list resp:", resp_email.read().decode("utf-8")[:300])