# app.py # test_internet.py import os import socket import ssl import sys import urllib.request import asyncio import httpx def test_dns(url: str): print(f"šŸ” Testing DNS resolution for {url}...") try: ip = socket.gethostbyname(url) print(f"āœ… DNS OK: {url} -> {ip}") return True except Exception as e: print(f"āŒ DNS FAILED: {e}") return False def test_https_urllib(url: str): print(f"\n🌐 Testing HTTPS access via urllib (Python stdlib) for {url}...") try: with urllib.request.urlopen(url, timeout=10) as response: print(f"āœ… HTTPS OK: status {response.getcode()}") return True except Exception as e: print(f"āŒ HTTPS FAILED (urllib): {e}") return False async def test_https_httpx(url: str): print(f"\nšŸš€ Testing HTTPS access via httpx (used by python-telegram-bot) for {url}...") try: async with httpx.AsyncClient(timeout=10) as client: resp = await client.get(url) print(f"āœ… HTTPS OK (httpx): status {resp.status_code}") return True except Exception as e: print(f"āŒ HTTPS FAILED (httpx): {e}") return False def test(host: str): url = f"https://{host}" dns_ok = test_dns(host) urllib_ok = test_https_urllib(url) if dns_ok else False httpx_ok = asyncio.run(test_https_httpx(url)) if dns_ok else False print("\n" + "="*60) if dns_ok and (urllib_ok or httpx_ok): print("šŸŽ‰ SUCCESS: Outbound internet appears to work!") else: print("šŸ›‘ FAILURE: Outbound internet is BLOCKED.") print(" → Telegram bots will NOT work on this platform.") print("="*60) if __name__ == "__main__": print("="*60) print("šŸ“” Hugging Face Space: Internet Access Test for Telegram") print("="*60) test("api.telegram.org") test("www.google.com") test("chat.qwen.ai")