Bad Request: bad webhook — every setWebhook error, its cause and the fix
Telegram tried the address you gave setWebhook, could not use it, and set nothing. The words after bad webhook say why: an http:// URL, a port other than 443, 80, 88 or 8443, a host that does not resolve, or a host that resolves to a private or IPv6-only address. Fix the URL or the DNS record and call setWebhook again.
By Livops team, the people who build and run LivopsUpdated
The full error, as the Telegram Bot API returns it from setWebhook with error code 400[4]:
Bad Request: bad webhook: An HTTPS URL must be provided for webhook
The part after bad webhook: changes with the reason, and that part is what tells you what to fix. Your library wraps it in its own words:
| Library | What you see |
|---|---|
| aiogram 3 | TelegramBadRequest: Telegram server says - Bad Request: bad webhook: An HTTPS URL must be provided for webhook[14][15] |
| python-telegram-bot | telegram.error.BadRequest: Bad webhook: an https url must be provided for webhook[16][17] |
This page lists every bad webhook reason the open-source Bot API server can return, with its cause and its fix, then covers the related setWebhook errors that use other words, the certificate rules as Telegram states them, what setWebhook does not check, and how a webhook is set on Livops.
What does the error mean?
When you call setWebhook, the Bot API server does not just store the URL. It parses it, checks the scheme and the port, resolves the host and checks the address it gets, and only then answers. If any of these steps fails, it returns Bad Request: bad webhook: followed by the reason, and it clears the webhook it was about to set[4][5]. So after this error the bot has no webhook, and the fix is always the same shape: correct the address, or the DNS record behind it, and call setWebhook again.
Telegram publishes the server’s source code and says you can run it yourself[1]; the messages below come from that code. Telegram also says the numeric error_code may change in the future[1], so match on the description, not on the number alone.
Every bad webhook message: cause and fix
| Exact message | Cause | Fix |
|---|---|---|
Bad Request: bad webhook: An HTTPS URL must be provided for webhook |
The url starts with http://[5]. Plain-HTTP webhooks are not possible[2] |
Use https:// and serve TLS 1.2 or newer on the host[2] |
Bad Request: bad webhook: Webhook can be set up only on ports 80, 88, 443 or 8443 |
The URL names any other port, for example :8080 or :5000[5] |
Serve on 443, 80, 88 or 8443[1], or put a proxy on 443 in front of the app and drop the port from the URL |
Bad Request: bad webhook: Failed to resolve host: <reason> |
The host name has no DNS answer the server can use; <reason> is the resolver’s own text[7] |
Create the A record, or wait until it has propagated, then try again |
Bad Request: bad webhook: IP address <ip> is reserved |
The host, or the ip_address you passed, is a private, loopback or other reserved address[5][7] |
Point the host at the server’s public IPv4 address |
Bad Request: bad webhook: IPv6-only addresses are not allowed |
The host resolves only to IPv6[5][7]; webhooks need IPv4[2] | Add an A record next to the AAAA record |
Bad Request: bad webhook: Invalid IP address specified |
The ip_address parameter is not a valid IP address[5] |
Pass a plain IPv4 address, or leave ip_address out |
Bad Request: bad webhook: Failed to set custom certificate file (followed by OpenSSL’s detail in braces) |
The file in the certificate parameter could not be loaded as a certificate[11][5] |
Upload the public certificate in PEM format, not the private key and not a string[2][1] |
Some notes on the rows:
- Failed to resolve host. The server resolves with the system resolver by default[9][10], and
<reason>is that resolver’s message[7]. On a Linux resolver built on glibc, a name that does not exist readsName or service not known, and a DNS server that did not answer readsTemporary failure in name resolution[13]. By default the open-source server caches a failed lookup for 5 minutes and a successful one for 29[9][10], so right after you add the record the old answer may still come back for a few minutes. - Reserved addresses. The list follows IANA’s special-purpose registry and includes
127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10(carrier-grade NAT) and the documentation ranges such as203.0.113.0/24[7].https://localhost/...resolves to127.0.0.1and fails here. - Port 80 is still HTTPS. The port rule applies to HTTPS URLs, and HTTP is refused on every port[5]. A webhook on port 80 must speak TLS on port 80[2].
- A local Bot API server is different. A server you run yourself with
--localaccepts HTTP URLs, any port and local IP addresses for the webhook[1]; the port, HTTPS and reserved-address checks are skipped in that mode[5][7].
The older wording
Before December 2022 the first message read HTTPS url must be provided for webhook, without the article and with url in lower case; the commit that changed it also added the IPv6 check[6]. Old answers and old logs quote the older text. It is the same error.
The lower-case python-telegram-bot form
python-telegram-bot strips a leading Bad Request: from Telegram’s description and capitalizes the rest[16], and Python’s capitalize() lowercases every letter after the first. So it prints Bad webhook: webhook can be set up only on ports 80, 88, 443 or 8443 and Bad webhook: failed to resolve host: name or service not known. The exception class is telegram.error.BadRequest[17]. aiogram keeps Telegram’s text as it is, in TelegramBadRequest[14].
Errors from setWebhook that do not say bad webhook
The same call has a few errors of its own, checked before the address is tried[4][18]:
| Exact message | Cause |
|---|---|
Bad Request: invalid webhook URL specified |
The url does not parse: an unsupported scheme such as ftp://, an empty host, or a port above 65535[4][8] |
Bad Request: secret token is too long |
secret_token is over 256 characters[4][1] |
Bad Request: secret token contains illegal characters |
secret_token uses something other than A-Z, a-z, 0-9, _ and -[4][1] |
Bad Request: certificate size is too big (<n> bytes) |
The uploaded certificate file is over 3 MB[4][18] |
A URL without a scheme is read as https://[4][8], so bot.example.com/hook is accepted as https://bot.example.com/hook.
What setWebhook does not check
In the open-source server’s code, setWebhook answers true with the description Webhook was set as soon as it has opened a connection to your address[4][5]. The connection is opened without waiting for it to complete[12], so the TLS handshake, the certificate and your app’s answer are not tested at this point. So a wrong certificate or nothing listening on the port usually does not produce bad webhook; the call succeeds, deliveries fail, and the reason appears in getWebhookInfo as last_error_message[1]. Read it there: getWebhookInfo: why your Telegram webhook fails.
The certificate rules, as Telegram states them
What Telegram asks of the server behind the URL[2]:
- IPv4, with IPv6 not supported for webhooks.
- Port 443, 80, 88 or 8443, open to Telegram’s subnets
149.154.160.0/20and91.108.4.0/22if you filter traffic; Telegram notes the range may change. - TLS 1.2 or newer.
- A certificate whose CN or a SAN matches the domain in the URL, with all intermediate certificates supplied to complete the chain.
- A certificate authority whose root Telegram trusts. If yours is not on Telegram’s list, you may upload the root certificate the same way as a self-signed one.
The FAQ adds that wildcard certificates may not be supported, that redirects are not supported, and that the CN must match your domain exactly[3].
A self-signed certificate has to be uploaded with the certificate parameter. Send it as a file (InputFile); sending it as a string does not work[1][3]. The file goes as multipart/form-data, in PEM format, and with a self-signed certificate you may use the server’s IP address as the CN instead of a domain name[2]. Telegram’s own guide generates the pair with OpenSSL[2]:
openssl req -newkey rsa:2048 -sha256 -nodes -keyout YOURPRIVATE.key -x509 -days 365 \
-out YOURPUBLIC.pem -subj "/CN=bot.example.com"
Then set the webhook with the public half, as a file upload:
curl -F "url=https://bot.example.com:8443/webhook" \
-F "[email protected]" \
"https://api.telegram.org/bot<TOKEN>/setWebhook"
YOURPRIVATE.key stays on your server for the web server’s TLS; never upload it. After a successful upload, getWebhookInfo reports has_custom_certificate: true[1].
To see what Telegram will see, Telegram’s guide suggests connecting with TLS 1.2 forced and SNI set[2]:
openssl s_client -tls1_2 -connect bot.example.com:443 -servername bot.example.com
Or skip the webhook
Every row above is about reaching your server from outside. Polling needs none of it: no domain, no port, no certificate. The bot asks Telegram for updates instead, and a bot uses one way or the other, never both. The trade-off is in Telegram webhook vs polling.
On Livops
On Livops a bot does not need to call setWebhook at all:
- Webhook mode sets it for you. Switch the bot’s Connection to Telegram to Webhook in its settings. On each deploy, once the new version answers on
PORT, Livops callssetWebhookwith the platform’s ownhttps://hook address, which carries no port and so is on 443, and with aWEBHOOK_SECRETit generates. Your code listens onPORT, receives onWEBHOOK_PATHand checksWEBHOOK_SECRET; the token must be inBOT_TOKEN. - The address is never your domain. The webhook goes to the platform’s hook address even if you attached a domain, so a DNS change on your side cannot turn into
Failed to resolve host. - If Telegram refuses, the deploy log says the webhook was not set and quotes Telegram’s sentence, and the deploy itself does not fail. If your own code calls
setWebhookwith another address, the platform’s next check puts its address back, so leave that call out. - A webhook in your own web service. If a
webservice receives the updates and callssetWebhookitself, its<name>.livops.appaddress already has HTTPS with a certificate issued automatically, and so does your own domain once its status is live; use the address with no port. See Domains.
How the two modes compare on the platform is in Telegram webhook vs polling. A bot costs 19 credits a month (19,000 so’m) in either mode; see Pricing.
Questions
Is a webhook set after Bad Request bad webhook?
No. The Bot API server drops the new address when its check fails, so the bot has no webhook at all, not the old one and not the new one. Fix the address and call setWebhook again, then confirm with getWebhookInfo.
Which ports does a Telegram webhook accept?
443, 80, 88 and 8443, and the address must be HTTPS on all four, port 80 included. Any other port returns bad webhook: Webhook can be set up only on ports 80, 88, 443 or 8443.
Can I use localhost or a LAN address for the webhook?
Not with api.telegram.org. Addresses such as 127.0.0.1, 10.x, 172.16.x to 172.31.x, 192.168.x and 100.64.x are reserved, and setWebhook answers IP address is reserved. Use a public address, or polling while you develop.
Why does python-telegram-bot print the message in lower case?
python-telegram-bot removes the Bad Request prefix from Telegram's description and capitalizes what is left, which lowercases every other letter. Bad webhook: an https url must be provided for webhook is the same error as Telegram's An HTTPS URL must be provided for webhook.
setWebhook returned true but no updates arrive. Is that the same error?
No. setWebhook returns true as soon as Telegram can open a connection to the address; it does not wait for TLS. A certificate or handshake problem shows up later in getWebhookInfo as last_error_message.
Do I need to upload a certificate?
Only for a self-signed certificate, or a verified one whose root Telegram does not trust. Upload the public certificate in PEM format with the certificate parameter, as a file in a multipart request; sending it as a string does not work.
Do I need to call setWebhook on Livops?
No. Switch the bot to webhook in its settings and Livops calls setWebhook itself with its own HTTPS address and a secret it generates. If your code also calls setWebhook, the platform's next check puts its own address back.
Sources
- Telegram Bot API — Making requests, setWebhook, WebhookInfo, Using a Local Bot API Server (core.telegram.org). Checked .
- Telegram — Marvin's Marvellous Guide to All Things Webhook (core.telegram.org). Checked .
- Telegram — Bots FAQ (core.telegram.org). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
- Telegram Bot API server source — telegram-bot-api/WebhookActor.cpp (raw.githubusercontent.com). Checked .
- telegram-bot-api commit b005f42 — Improve error messages (December 2022) (github.com). Checked .
- TDLib source — tdutils/td/utils/port/IPAddress.cpp (raw.githubusercontent.com). Checked .
- TDLib source — tdutils/td/utils/HttpUrl.cpp (raw.githubusercontent.com). Checked .
- TDLib source — tdnet/td/net/GetHostByNameActor.h (raw.githubusercontent.com). Checked .
- Telegram Bot API server source — telegram-bot-api/telegram-bot-api.cpp (raw.githubusercontent.com). Checked .
- TDLib source — tdnet/td/net/SslCtx.cpp (raw.githubusercontent.com). Checked .
- TDLib source — tdutils/td/utils/port/SocketFd.cpp (raw.githubusercontent.com). Checked .
- glibc source — sysdeps/posix/gai_strerror-strs.h (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.h (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- getWebhookInfo: check why your Telegram webhook is not workingCall https://api.telegram.org/bot<TOKEN>/getWebhookInfo. An empty url means no webhook is set. A pending_update_count that keeps growing with a recent last_error_date means Telegram cannot deliver, and last_error_message says why: a non-2XX answer, a timeout, a TLS error. Fix the endpoint, then reset with setWebhook, or deleteWebhook with drop_pending_updates to discard the backlog.
- Telegram bot webhook vs polling: which one to usePolling means your bot asks Telegram for updates in a loop; a webhook means Telegram POSTs each update to your HTTPS address. Polling is simpler and needs no address; a webhook needs HTTPS but no always-running loop. A bot uses one or the other, never both. On Livops both run for the same 19 credits a month.
- 502 Bad Gateway after deploying: what it means and how to fix itThe proxy in front of your app reached for it and got no valid answer: nothing was listening on the port it tried, or the process closed the connection mid-request. After a deploy that is almost always one of five things: the app listens on the wrong port or on 127.0.0.1, it crashed on start, it was still starting, it ran out of memory, or the proxy points at the wrong port. The app's own log says which.
- 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.
- 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.
- python-telegram-bot hosting: deploying a v22 botA python-telegram-bot bot runs as one Application: run_polling() for polling, run_webhook() with the webhooks extra for a webhook. Both stop cleanly on SIGTERM. On Livops it runs from a push with bot.py and requirements.txt for 19 credits a month (19,000 so'm).