douyinWEB/scripts/_probe_oauth_cause.py
2026-09-13 22:10:49 -05:00

40 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r'''#!/bin/bash
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app import db
chs = db.list_shorts_channels()
print("=== shorts channels by profile ===")
for c in sorted(chs, key=lambda x: (str(x.get("oauth_profile_id") or ""), str(x.get("name") or ""))):
if not c.get("enabled"):
continue
err=(c.get("oauth_error") or "").replace("\n"," ")[:90]
print(f"profile={c.get('oauth_profile_id') or '-'} | oauth_ok={c.get('oauth_ok')} | {c.get('name')} | err={err!r}")
# recent settings related to shorts / quota
cfg=db.get_settings_map()
for k in sorted(cfg):
if "shorts" in k.lower() and ("quota" in k.lower() or "cooldown" in k.lower() or "enabled" in k.lower()):
print("setting", k, "=", cfg.get(k))
PY
echo '=== recent api log oauth/refresh/revoked ==='
journalctl -u douyinweb-api --since "24 hours ago" --no-pager 2>/dev/null | grep -iE 'revoked|invalid_grant|OAuth 刷新|refresh.*fail|quota' | tail -40
'''
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file("/tmp/_probe_oauth_cause.sh", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command("bash /tmp/_probe_oauth_cause.sh", timeout=60)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()