TelegramNetworkError: HTTP Client says - ClientConnectorError (aiogram): how to fix it
aiogram.exceptions.TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 means the bot could not open a connection to Telegram's Bot API at all: the code and the token are not the problem, the network is. The usual causes are a network that blocks Telegram, DNS, a missing or broken proxy, a bad IPv6 route, a server with no outbound access, or a slow path that ends in timeouts. Test the same path with curl, then fix the network, set aiogram's proxy, or run the bot where api.telegram.org is reachable.
By Livops team, the people who build and run LivopsUpdated
The bot stops at start, or its log fills with lines like these:
aiogram.exceptions.TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [Connect call failed ('149.154.166.110', 443)]
Failed to fetch updates - TelegramNetworkError: HTTP Client says - ClientConnectorError: Cannot connect to host api.telegram.org:443 ssl:default [...]
Sleep for 1.000000 seconds and try again... (tryings = 0, bot id = 123456789)
The bot cannot reach api.telegram.org. This page explains what aiogram’s message says, shows how to test the same connection with curl, lists the causes from the most common, and covers aiogram’s proxy and session settings. It ends with why moving the bot to a network that reaches Telegram fixes it without a line of code.
What does the error mean?
Every Bot API call is an HTTPS request to https://api.telegram.org/bot<token>/METHOD_NAME[1]. aiogram sends it with aiohttp. When aiohttp raises a client error, aiogram catches it and raises TelegramNetworkError instead, with the error’s class name and text as the message[2]; the exception’s label is HTTP Client says[3]. A timeout becomes Request timeout error instead[2]. aiogram removes the bot token from the message and keeps the original aiohttp error on the exception’s original attribute[2][3].
ClientConnectorError is aiohttp’s error for a connection that could not be established[7]. Its text is Cannot connect to host <host>:<port> ssl:<ssl> [<reason>][7], and the reason in brackets comes from the operating system. Connect call failed ('<address>', 443) is what Python’s asyncio reports when the TCP connection to that address fails[9]. So nothing was sent: the token, the handlers and the Bot API are not involved yet. The problem is the path from your machine to Telegram.
Where it shows up
- At start, it ends the process.
start_pollingfirst callsgetMeto learn the bot’s name, outside the retry loop[5]. If Telegram is unreachable then, the exception goes up throughstart_pollingand the bot exits.getMeis the Bot API’s method for testing a token[1], so it is usually the first call to fail. - While polling, it is retried. A failed
getUpdatesis logged asFailed to fetch updates - ..., followed bySleep for ... seconds and try again...; the delay grows from 1 to 5 seconds, andConnection establishedis logged when a request works again[5]. A few such lines during a network hiccup are harmless. A steady stream means the bot cannot reach Telegram. - In a handler,
await message.answer(...)raises it like any other exception.
The class name says which step failed
aiogram prints the exact aiohttp class[2], and aiohttp has a subclass per step[8][7]:
| In the message | What failed |
|---|---|
ClientConnectorDNSError |
Resolving api.telegram.org to an address |
ClientConnectorError |
Opening the TCP connection: refused, unreachable, or no answer |
ClientProxyConnectionError |
Connecting to the proxy |
ClientConnectorSSLError, ClientConnectorCertificateError |
The TLS handshake or the certificate check |
Request timeout error |
The connection worked, but the answer did not come in time; see Timed out |
Test the connection with curl
Run this on the machine where the bot runs, in the same container if it runs in one:
curl -sS -o /dev/null --noproxy '*' --connect-timeout 10 \
-w 'dns %{time_namelookup}s tcp %{time_connect}s tls %{time_appconnect}s http %{http_code}\n' \
"https://api.telegram.org/bot$BOT_TOKEN/getMe"
--connect-timeout limits only the connection phase[10]. The -w variables are the seconds until name resolving finished, until the TCP connection was made, and until the TLS handshake finished, plus the HTTP code[10]. --noproxy '*' disables any proxy curl would take from the environment[10], which matches aiogram: aiohttp reads proxy settings from the environment only when trust_env is on, and it is off by default[8]; aiogram creates its session without it[2].
What the result tells you:
Could not resolve host: DNS. See cause 2.- No connection within 10 seconds, or
Connection refused: the network or a firewall drops the traffic. See causes 1 and 5. http 200: this machine reaches Telegram. If the bot still fails, it runs somewhere else (another container, another host), or through a proxy curl did not use.http 401: the network works, the token does not. See 401 Unauthorized.
Then compare the address families. -4 makes curl request only IPv4 addresses, -6 only IPv6[10]:
curl -4 -sS -o /dev/null -w '%{http_code}\n' --connect-timeout 10 "https://api.telegram.org/bot$BOT_TOKEN/getMe"
curl -6 -sS -o /dev/null -w '%{http_code}\n' --connect-timeout 10 "https://api.telegram.org/bot$BOT_TOKEN/getMe"
And if you have a proxy, test it on its own with -x, which takes http://, socks4://, socks5:// and socks5h:// proxies[10]:
curl -sS -o /dev/null -w '%{http_code}\n' -x socks5h://user:[email protected]:1080 "https://api.telegram.org/bot$BOT_TOKEN/getMe"
Keep the token out of anything you paste into a chat or an issue.
Causes, most common first
1. The network blocks Telegram
A firewall, the hosting provider or the network operator drops connections to Telegram’s addresses. curl hangs at tcp and then gives up; aiogram shows ClientConnectorError with a connect failure, or a timeout. Nothing in the code fixes this: run the bot on a network that reaches Telegram, or send its traffic through a proxy that does (cause 3).
2. DNS does not resolve api.telegram.org
The message names ClientConnectorDNSError[8], and curl says it could not resolve the host. The machine’s resolver is down, wrong, or filters the name. Fix the resolver the system uses, then restart the bot: aiogram’s connector caches DNS answers for an hour (ttl_dns_cache=3600)[2], so a running bot can keep a stale answer after you fix DNS.
3. A proxy is needed but not used, or is broken
On a network that only reaches the internet through a proxy, the usual trap is the environment: HTTPS_PROXY is set, curl and pip use it, and aiogram ignores it, because aiohttp reads proxy variables only with trust_env on[8] and aiogram does not turn it on[2]. Pass the proxy to aiogram explicitly; see the settings below.
When the proxy itself fails, the error is about the proxy, not Telegram: test it with curl -x as above.
4. A broken IPv6 route
If api.telegram.org resolves to IPv6 addresses on your server, and the server has IPv6 configured but its route does not work, connections to those addresses fail. By default aiohttp accepts both families[8] and uses Happy Eyeballs, starting the next connection attempt after 0.25 seconds[8], so a dead IPv6 route usually costs a moment rather than the connection. If curl -6 fails, curl -4 works and the bot still fails, fix IPv6 on the server or force IPv4 in aiogram, below.
5. The server has no outbound access
Some machines are not allowed to open connections to the internet at all: a private network without a NAT gateway, a container network with egress rules, a firewall that allows only listed hosts. Inbound traffic may work, so a website on the same machine answers, while every outbound request fails. curl from the machine fails the same way. Open outbound HTTPS to api.telegram.org, or run the bot elsewhere.
6. A slow path ends in timeouts
When the connection opens but is slow, the error reads HTTP Client says - Request timeout error instead[2]. aiogram’s session allows 60 seconds per request by default[4]. For long polling it waits the session timeout plus the polling timeout[5]. Timeouts, and when to raise them, are covered in Timed out.
aiogram’s proxy and session settings
All of these go on AiohttpSession, which aiogram uses by default[6], passed to the Bot:
import os
from aiogram import Bot
from aiogram.client.session.aiohttp import AiohttpSession
session = AiohttpSession(
proxy=os.environ.get("TELEGRAM_PROXY"), # e.g. socks5://user:password@host:1080, or unset
timeout=90, # seconds per request; the default is 60
)
bot = Bot(token=os.environ["BOT_TOKEN"], session=session)
- The proxy needs
aiohttp-socks. Without it,AiohttpSession(proxy=...)raisesRuntimeErrorasking you to install it[2][6]. Addaiohttp-sockstorequirements.txt. - Supported proxies are
http(tunnelling),socks4(a)andsocks5[6]. Credentials go in the URL, or as anaiohttp.BasicAuthin a(url, auth)tuple; an iterable of proxies makes a chain[6]. - DNS goes through the proxy. aiogram asks the proxy to resolve names (
rdns=True)[2], so a broken local resolver does not matter once a proxy is set. timeoutis the session’s request timeout[4]. Raising it helps a slow path; it does nothing for a connection that cannot open.- Retries while polling follow
backoff_config, aBackoffConfigwithmin_delay=1.0, max_delay=5.0, factor=1.3, jitter=0.1by default; pass your own tostart_polling[5].
Wait for Telegram at start instead of exiting
Since the first getMe is not retried[5], a bot that starts while the network is down exits. If you would rather have it wait:
import asyncio
import logging
import os
from aiogram import Bot, Dispatcher
from aiogram.exceptions import TelegramNetworkError
dp = Dispatcher()
async def wait_for_telegram(bot: Bot) -> None:
delay = 1
while True:
try:
await bot.get_me()
return
except TelegramNetworkError as e:
logging.warning("Telegram unreachable (%s), retrying in %s s", e, delay)
await asyncio.sleep(delay)
delay = min(delay * 2, 60)
async def main() -> None:
bot = Bot(token=os.environ["BOT_TOKEN"])
await wait_for_telegram(bot)
await dp.start_polling(bot)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(main())
This rides out a short outage. It does not fix a network that never reaches Telegram; the warning in the log keeps saying so.
Force IPv4, as a last resort
AiohttpSession takes no address-family argument: it builds aiohttp’s TCPConnector from its own internal settings[2]. aiohttp’s connector takes family=socket.AF_INET for IPv4 only[8], and that setting can be added before the first request:
import socket
session = AiohttpSession()
session._connector_init["family"] = socket.AF_INET # private attribute: re-check after upgrading aiogram
_connector_init is internal to aiogram and can change in any release. Fixing the server’s IPv6 route is the better fix.
Why running the bot where Telegram is reachable fixes it
ClientConnectorError is a property of the network the bot runs in, not of the bot. The same code, on a machine where the curl check above returns http 200, connects. That is why the error often appears after a move: from a laptop to a server, from one provider or country to another, or into a container network with stricter rules.
A webhook does not get around it. With a webhook Telegram delivers updates to you, and you can answer one update with one method in the webhook’s reply, but you cannot see whether that request succeeded[1]. Everything else the bot does, sending messages and files included, is still a request to api.telegram.org. The bot needs outbound access to Telegram either way.
The move does not cost the messages sent meanwhile, within limits: Telegram keeps incoming updates on its server until the bot receives them, but not longer than 24 hours[1].
On Livops
- Test before you move. The deciding check is the curl test above, run from where the bot will run. Livops’s servers are in Uzbekistan. A bot runs there around the clock, and both polling and webhooks work. If you choose a webhook, Livops gives Telegram the address itself.
- Where you see it. A bot that exits on this error at start fails its deploy as
start_failed, and the traceback is on the project’s Logs page. A bot’s previous version is stopped before the new one starts, because two copies polling Telegram would conflict, so the bot is down until a deploy succeeds. - Settings as variables. Put
BOT_TOKEN, andTELEGRAM_PROXYif you use one, under Settings → Variables, mark the token as a secret, and read them as in the code above. New values take effect on the next deploy; restart the service to apply them now. - The start command. For an aiogram bot, write
.venv/bin/python bot.pyin Settings → Start, or aProcfilewithworker: .venv/bin/python bot.py.
A bot costs 19 credits a month (19,000 so’m). Hosting an aiogram bot, step by step: aiogram bot hosting. Startup failures in the docs: The app did not start. If the bot connects but runs twice, see Conflict: terminated by other getUpdates request.
Questions
What does TelegramNetworkError HTTP Client says ClientConnectorError mean?
aiogram tried to open a connection to api.telegram.org on port 443 and could not. aiohttp raised ClientConnectorError, and aiogram wrapped it in TelegramNetworkError with the label HTTP Client says. The request never reached Telegram, so the token and the handlers are not the cause; the network between the bot and Telegram is.
Why does the bot crash at start but only log errors later?
start_polling first calls getMe to learn the bot's name, and that call is not retried, so a network error there ends the process. Once polling runs, a failed getUpdates is logged as Failed to fetch updates and retried with a delay that grows from 1 to 5 seconds.
curl reaches api.telegram.org but the bot does not. Why?
Most often curl uses a proxy from the HTTPS_PROXY or ALL_PROXY environment variables and aiogram does not: aiohttp ignores those variables unless trust_env is on, and aiogram does not turn it on. Run curl with --noproxy '*' to test the path aiogram takes, and pass the proxy to AiohttpSession explicitly.
How do I use a proxy with aiogram 3?
Install aiohttp-socks and create the bot with Bot(token, session=AiohttpSession(proxy='socks5://user:password@host:1080')). aiogram supports http tunnelling, socks4, socks4a and socks5 proxies, credentials in the URL or as aiohttp.BasicAuth, and proxy chains.
Is it a timeout or a connection error?
Read the text after HTTP Client says. ClientConnectorError, or one of its subclasses such as ClientConnectorDNSError, means no connection was opened. Request timeout error means the request did not finish within the session's limit, 60 seconds by default; that case has its own guide.
Will a webhook instead of polling fix it?
No. With a webhook Telegram connects to your bot to deliver updates, but sending messages, files and every other method is still a request from the bot to api.telegram.org. The bot needs outbound access to Telegram either way.
Do I lose messages while the bot cannot reach Telegram?
Not right away. Telegram keeps incoming updates on its server until the bot receives them, but not longer than 24 hours. Restore the connection within that window and the bot gets the queued updates.
Sources
- Telegram Bot API — Making requests, Getting updates, getMe (core.telegram.org). Checked .
- aiogram source — aiogram/client/session/aiohttp.py (v3.34.0) (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/exceptions.py (v3.34.0) (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/client/session/base.py (v3.34.0) (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/dispatcher/dispatcher.py (v3.34.0) (raw.githubusercontent.com). Checked .
- aiogram documentation — Aiohttp session (docs.aiogram.dev). Checked .
- aiohttp source — aiohttp/client_exceptions.py (v3.14.5) (raw.githubusercontent.com). Checked .
- aiohttp docs — Client reference (ClientSession, TCPConnector, exceptions) (docs.aiohttp.org). Checked .
- CPython source — Lib/asyncio/selector_events.py (3.13) (raw.githubusercontent.com). Checked .
- curl — man page (curl.se). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- aiogram bot hosting: how to deploy an aiogram 3 botAn aiogram 3 bot needs one process that never stops, the token in an environment variable, state kept outside memory and a clean exit on SIGTERM. On Livops you push a repository with bot.py and requirements.txt, and it runs for 19 credits a month (19,000 so'm), polling or webhook.
- telegram.error.TimedOut: Timed out — how to fix Telegram bot timeoutstelegram.error.TimedOut: Timed out in python-telegram-bot, TelegramNetworkError: HTTP Client says - Request timeout error in aiogram, and HttpError in grammY all mean the bot's request to the Bot API got no answer in time. Most often a file upload needs longer than the default timeout, or the connection, DNS or a proxy on the way to api.telegram.org is slow. Raise the timeouts for media, retry with backoff, and test the connection with curl.
- Conflict: terminated by other getUpdates request — how to fix itTelegram is telling your bot that another process called getUpdates with the same token and took the connection over. Two copies of the bot are polling at once: stop the other one (usually the copy still running on your computer or an old server), or get a new token from @BotFather, and the error stops.
- [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate in Python: how to fix itssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate means Python could not build a chain from the server's certificate to a root it trusts. In requests, httpx, aiohttp and urllib the usual causes are a missing or outdated CA bundle, a python.org install on macOS that never ran Install Certificates.command, a corporate proxy that re-signs HTTPS, or a server that does not send its intermediate certificate. Fix the trust store; do not turn verification off.
- Telegram 401 Unauthorized, InvalidToken, TokenValidationError — how to fix the bot token401 Unauthorized means Telegram does not accept your bot's token: it is mistyped, has a space, quote or newline around it, was replaced in @BotFather, belongs to a deleted bot, or never reached the server because the variable is not set. Call getMe with curl to see what Telegram says, put the current token from @BotFather in the variable, and start the bot again.
- How to keep a Telegram bot running 24/7A bot run with python bot.py or node bot.js stops when the terminal closes, the laptop sleeps or the code crashes, and two copies polling one token knock each other off with 409 Conflict. Keep exactly one copy running under something that restarts it — systemd, Docker or a platform — and stop it cleanly on SIGTERM. On Livops a bot runs from a push for 19 credits a month (19,000 so'm).
- ImportError: cannot import name 'executor' from 'aiogram': how to fix itImportError: cannot import name 'executor' from 'aiogram' means code written for aiogram 2 is running on aiogram 3, which removed executor entirely. Rewrite the start for aiogram 3: Dispatcher() without the bot, handlers registered with @dp.message, and await dp.start_polling(bot) inside asyncio.run(main()). Pinning aiogram below 3 only postpones that rewrite.
- Telegram bot hosting in 2026: the options comparedA Telegram bot needs a process that never stops, or a public HTTPS address for a webhook. On Livops it runs from a GitHub push for 19 credits a month (19,000 so'm). Here is how a VPS, Railway, Render, Fly.io and Vercel compare.