Spaces:
Runtime error
Runtime error
remove diag
Browse files
diag.py
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import socket
|
| 3 |
-
import traceback
|
| 4 |
-
import requests
|
| 5 |
-
|
| 6 |
-
H = {
|
| 7 |
-
"BOT_TOKEN": os.environ.get("BOT_TOKEN", ""),
|
| 8 |
-
"HF_TOKEN": os.environ.get("HF_TOKEN", ""),
|
| 9 |
-
"DATA_REPO": os.environ.get("DATA_REPO", ""),
|
| 10 |
-
}
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def log(msg):
|
| 14 |
-
print(msg, flush=True)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def main():
|
| 18 |
-
lines = []
|
| 19 |
-
log = lambda m: (lines.append(m), print(m, flush=True))
|
| 20 |
-
log("=== DIAG START ===")
|
| 21 |
-
log("proxy env: " + str({k: v for k, v in os.environ.items()
|
| 22 |
-
if "proxy" in k.lower()}))
|
| 23 |
-
log("http_proxy: " + str(os.environ.get("http_proxy")))
|
| 24 |
-
log("https_proxy: " + str(os.environ.get("https_proxy")))
|
| 25 |
-
log("HTTP_PROXY: " + str(os.environ.get("HTTP_PROXY")))
|
| 26 |
-
log("HTTPS_PROXY: " + str(os.environ.get("HTTPS_PROXY")))
|
| 27 |
-
log("NO_PROXY: " + str(os.environ.get("NO_PROXY")))
|
| 28 |
-
log("no_proxy: " + str(os.environ.get("no_proxy")))
|
| 29 |
-
|
| 30 |
-
try:
|
| 31 |
-
ips = socket.getaddrinfo("api.telegram.org", 443)
|
| 32 |
-
log("api.telegram.org resolves: " + str([ip[4][0] for ip in ips[:6]]))
|
| 33 |
-
except Exception as e:
|
| 34 |
-
log("DNS api.telegram.org FAILED: " + str(e))
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
ips = socket.getaddrinfo("huggingface.co", 443)
|
| 38 |
-
log("huggingface.co resolves: " + str([ip[4][0] for ip in ips[:6]]))
|
| 39 |
-
except Exception as e:
|
| 40 |
-
log("DNS huggingface.co FAILED: " + str(e))
|
| 41 |
-
|
| 42 |
-
for url in [
|
| 43 |
-
"https://api.telegram.org/",
|
| 44 |
-
"https://api.telegram.org/bot" + H["BOT_TOKEN"] + "/getMe",
|
| 45 |
-
"https://huggingface.co/",
|
| 46 |
-
"https://www.google.com/",
|
| 47 |
-
]:
|
| 48 |
-
try:
|
| 49 |
-
r = requests.get(url, timeout=10)
|
| 50 |
-
log(f"GET {url[:50]} -> {r.status_code}")
|
| 51 |
-
except Exception as e:
|
| 52 |
-
log(f"GET {url[:50]} -> FAIL {type(e).__name__}: {str(e)[:150]}")
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import asyncio
|
| 56 |
-
from telegram import Bot
|
| 57 |
-
|
| 58 |
-
async def t():
|
| 59 |
-
b = Bot(token=H["BOT_TOKEN"])
|
| 60 |
-
me = await b.get_me()
|
| 61 |
-
log("PTB get_me OK: " + me.username)
|
| 62 |
-
|
| 63 |
-
asyncio.run(t())
|
| 64 |
-
except Exception as e:
|
| 65 |
-
log("PTB get_me FAIL: " + traceback.format_exc()[-1500:])
|
| 66 |
-
|
| 67 |
-
log("=== DIAG END ===")
|
| 68 |
-
|
| 69 |
-
try:
|
| 70 |
-
from datetime import datetime
|
| 71 |
-
import io
|
| 72 |
-
from huggingface_hub import HfApi
|
| 73 |
-
|
| 74 |
-
api = HfApi(token=H["HF_TOKEN"])
|
| 75 |
-
ts = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
|
| 76 |
-
api.upload_file(
|
| 77 |
-
path_or_fileobj=io.BytesIO("\n".join(lines).encode("utf-8")),
|
| 78 |
-
path_in_repo=f"logs/diag_{ts}.log",
|
| 79 |
-
repo_id=H["DATA_REPO"], repo_type="model",
|
| 80 |
-
commit_message="diag output",
|
| 81 |
-
)
|
| 82 |
-
print("diag log pushed", flush=True)
|
| 83 |
-
except Exception as e:
|
| 84 |
-
print("push failed:", e, flush=True)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
if __name__ == "__main__":
|
| 88 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|