Tg-bot / main.py
timchick18's picture
Update main.py
76df7a4 verified
Raw History Blame Contribute Delete
1.32 kB
import os
import httpx
from fastapi import FastAPI
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
@app.get("/")
async def test_internet():
target_url = "https://hosting-tg-bot.123razvlekuha123.workers.dev/"
logger.info(f"Попытка запроса к {target_url}")
try:
# Используем httpx для простого GET запроса
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(target_url)
return {
"status": "Успех!",
"message": "Сайт example.com доступен",
"http_code": response.status_code,
"content_snippet": response.text[:200] # Показываем кусочек кода сайта
}
except Exception as e:
logger.error(f"Ошибка запроса: {e}")
return {
"status": "Ошибка",
"error_type": str(type(e).__name__),
"error_message": str(e),
"hint": "Если здесь снова DNSError, значит DNS полностью заблокирован в этом Space"
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)