Sadeep Sachintha commited on
Commit ·
5cceeb9
1
Parent(s): 6b640dc
debug: add socket.getaddrinfo monkeypatch for api.telegram.org and fix name 'aiohttp' in diagnostics
Browse files
main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import logging
|
| 2 |
import socket
|
|
|
|
| 3 |
from contextlib import asynccontextmanager
|
| 4 |
from fastapi import FastAPI, Request, Response
|
| 5 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -9,6 +10,15 @@ from aiogram.client.session.aiohttp import AiohttpSession
|
|
| 9 |
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
| 10 |
from sqlalchemy import select, func
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
from core.config import settings
|
| 13 |
from db.session import init_db, async_session
|
| 14 |
from db.models import User, Subscription, Threshold
|
|
|
|
| 1 |
import logging
|
| 2 |
import socket
|
| 3 |
+
import aiohttp
|
| 4 |
from contextlib import asynccontextmanager
|
| 5 |
from fastapi import FastAPI, Request, Response
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 10 |
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
| 11 |
from sqlalchemy import select, func
|
| 12 |
|
| 13 |
+
# Monkeypatch socket.getaddrinfo to bypass DNS resolution blocks for api.telegram.org
|
| 14 |
+
original_getaddrinfo = socket.getaddrinfo
|
| 15 |
+
def custom_getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
|
| 16 |
+
if host == "api.telegram.org":
|
| 17 |
+
# Map to Telegram Bot API direct IP
|
| 18 |
+
return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', ('149.154.166.110', port))]
|
| 19 |
+
return original_getaddrinfo(host, port, family, type, proto, flags)
|
| 20 |
+
socket.getaddrinfo = custom_getaddrinfo
|
| 21 |
+
|
| 22 |
from core.config import settings
|
| 23 |
from db.session import init_db, async_session
|
| 24 |
from db.models import User, Subscription, Threshold
|