LucaR84 commited on
Commit
cb17166
Β·
verified Β·
1 Parent(s): 8cfb116

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -8,31 +8,31 @@ import urllib.request
8
  import asyncio
9
  import httpx
10
 
11
- def test_dns():
12
- print("πŸ” Testing DNS resolution for api.telegram.org...")
13
  try:
14
- ip = socket.gethostbyname("api.telegram.org")
15
- print(f"βœ… DNS OK: api.telegram.org -> {ip}")
16
  return True
17
  except Exception as e:
18
  print(f"❌ DNS FAILED: {e}")
19
  return False
20
 
21
- def test_https_urllib():
22
- print("\n🌐 Testing HTTPS access via urllib (Python stdlib)...")
23
  try:
24
- with urllib.request.urlopen("https://api.telegram.org", timeout=10) as response:
25
  print(f"βœ… HTTPS OK: status {response.getcode()}")
26
  return True
27
  except Exception as e:
28
  print(f"❌ HTTPS FAILED (urllib): {e}")
29
  return False
30
 
31
- async def test_https_httpx():
32
- print("\nπŸš€ Testing HTTPS access via httpx (used by python-telegram-bot)...")
33
  try:
34
  async with httpx.AsyncClient(timeout=10) as client:
35
- resp = await client.get("https://api.telegram.org")
36
  print(f"βœ… HTTPS OK (httpx): status {resp.status_code}")
37
  return True
38
  except Exception as e:
@@ -44,9 +44,17 @@ if __name__ == "__main__":
44
  print("πŸ“‘ Hugging Face Space: Internet Access Test for Telegram")
45
  print("="*60)
46
 
47
- dns_ok = test_dns()
48
- urllib_ok = test_https_urllib() if dns_ok else False
49
- httpx_ok = asyncio.run(test_https_httpx()) if dns_ok else False
 
 
 
 
 
 
 
 
50
 
51
  print("\n" + "="*60)
52
  if dns_ok and (urllib_ok or httpx_ok):
 
8
  import asyncio
9
  import httpx
10
 
11
+ def test_dns(url: str):
12
+ print(f"πŸ” Testing DNS resolution for {url}...")
13
  try:
14
+ ip = socket.gethostbyname(url)
15
+ print(f"βœ… DNS OK: {url} -> {ip}")
16
  return True
17
  except Exception as e:
18
  print(f"❌ DNS FAILED: {e}")
19
  return False
20
 
21
+ def test_https_urllib(url: str):
22
+ print(f"\n🌐 Testing HTTPS access via urllib (Python stdlib) for {url}...")
23
  try:
24
+ with urllib.request.urlopen(str, timeout=10) as response:
25
  print(f"βœ… HTTPS OK: status {response.getcode()}")
26
  return True
27
  except Exception as e:
28
  print(f"❌ HTTPS FAILED (urllib): {e}")
29
  return False
30
 
31
+ async def test_https_httpx(url: str):
32
+ print(f"\nπŸš€ Testing HTTPS access via httpx (used by python-telegram-bot) for {url}...")
33
  try:
34
  async with httpx.AsyncClient(timeout=10) as client:
35
+ resp = await client.get(url)
36
  print(f"βœ… HTTPS OK (httpx): status {resp.status_code}")
37
  return True
38
  except Exception as e:
 
44
  print("πŸ“‘ Hugging Face Space: Internet Access Test for Telegram")
45
  print("="*60)
46
 
47
+ dns_ok = test_dns("api.telegram.org")
48
+ urllib_ok = test_https_urllib("https://api.telegram.org") if dns_ok else False
49
+ httpx_ok = asyncio.run(test_https_httpx("https://api.telegram.org")) if dns_ok else False
50
+
51
+ dns_ok = test_dns("www.google.com")
52
+ urllib_ok = test_https_urllib("https://www.google.com") if dns_ok else False
53
+ httpx_ok = asyncio.run(test_https_httpx("https://www.google.com")) if dns_ok else False
54
+
55
+ dns_ok = test_dns("chat.qwen.ai")
56
+ urllib_ok = test_https_urllib("https://chat.qwen.ai") if dns_ok else False
57
+ httpx_ok = asyncio.run(test_https_httpx("https://chat.qwen.ai")) if dns_ok else False
58
 
59
  print("\n" + "="*60)
60
  if dns_ok and (urllib_ok or httpx_ok):