Spaces:
Runtime error
Runtime error
add diagnostic script
Browse files
diag.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
log("=== DIAG START ===")
|
| 19 |
+
log("proxy env: " + str({k: v for k, v in os.environ.items()
|
| 20 |
+
if "proxy" in k.lower()}))
|
| 21 |
+
log("http_proxy: " + str(os.environ.get("http_proxy")))
|
| 22 |
+
log("https_proxy: " + str(os.environ.get("https_proxy")))
|
| 23 |
+
log("HTTP_PROXY: " + str(os.environ.get("HTTP_PROXY")))
|
| 24 |
+
log("HTTPS_PROXY: " + str(os.environ.get("HTTPS_PROXY")))
|
| 25 |
+
log("NO_PROXY: " + str(os.environ.get("NO_PROXY")))
|
| 26 |
+
log("no_proxy: " + str(os.environ.get("no_proxy")))
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
ips = socket.getaddrinfo("api.telegram.org", 443)
|
| 30 |
+
log("api.telegram.org resolves: " + str([ip[4][0] for ip in ips[:6]]))
|
| 31 |
+
except Exception as e:
|
| 32 |
+
log("DNS api.telegram.org FAILED: " + str(e))
|
| 33 |
+
|
| 34 |
+
try:
|
| 35 |
+
ips = socket.getaddrinfo("huggingface.co", 443)
|
| 36 |
+
log("huggingface.co resolves: " + str([ip[4][0] for ip in ips[:6]]))
|
| 37 |
+
except Exception as e:
|
| 38 |
+
log("DNS huggingface.co FAILED: " + str(e))
|
| 39 |
+
|
| 40 |
+
for url in [
|
| 41 |
+
"https://api.telegram.org/",
|
| 42 |
+
"https://api.telegram.org/bot" + H["BOT_TOKEN"] + "/getMe",
|
| 43 |
+
"https://huggingface.co/",
|
| 44 |
+
"https://www.google.com/",
|
| 45 |
+
]:
|
| 46 |
+
try:
|
| 47 |
+
r = requests.get(url, timeout=10)
|
| 48 |
+
log(f"GET {url[:50]} -> {r.status_code}")
|
| 49 |
+
except Exception as e:
|
| 50 |
+
log(f"GET {url[:50]} -> FAIL {type(e).__name__}: {str(e)[:150]}")
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
import asyncio
|
| 54 |
+
from telegram import Bot
|
| 55 |
+
|
| 56 |
+
async def t():
|
| 57 |
+
b = Bot(token=H["BOT_TOKEN"])
|
| 58 |
+
me = await b.get_me()
|
| 59 |
+
log("PTB get_me OK: " + me.username)
|
| 60 |
+
|
| 61 |
+
asyncio.run(t())
|
| 62 |
+
except Exception as e:
|
| 63 |
+
log("PTB get_me FAIL: " + traceback.format_exc()[-1500:])
|
| 64 |
+
|
| 65 |
+
log("=== DIAG END ===")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
main()
|