# 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.

Source: https://livops.dev/en/guides/error-telegram-bad-webhook

By Livops team, the people who build and run Livops. Updated 3 December 2026.

The full error, as the Telegram Bot API returns it from `setWebhook` with error code 400[4]:

```text
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 reads `Name or service not known`, and a DNS server that did not answer reads `Temporary 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 as `203.0.113.0/24`[7]. `https://localhost/...` resolves to `127.0.0.1` and 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 `--local` accepts 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](https://livops.dev/en/guides/telegram-getwebhookinfo).

## 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/20` and `91.108.4.0/22` if 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]:

```sh
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:

```sh
curl -F "url=https://bot.example.com:8443/webhook" \
     -F "certificate=@YOURPUBLIC.pem" \
     "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]:

```sh
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](https://livops.dev/en/guides/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 calls `setWebhook` with the platform's own `https://` hook address, which carries no port and so is on 443, and with a `WEBHOOK_SECRET` it generates. Your code listens on `PORT`, receives on `WEBHOOK_PATH` and checks `WEBHOOK_SECRET`; the token must be in `BOT_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 `setWebhook` with 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 `web` service receives the updates and calls `setWebhook` itself, its `<name>.livops.app` address 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](https://livops.dev/en/docs/domains).

How the two modes compare on the platform is in [Telegram webhook vs polling](https://livops.dev/en/guides/telegram-webhook-vs-polling). A bot costs **19 credits a month (19,000 so'm)** in either mode; see [Pricing](https://livops.dev/en/docs/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

1. [Telegram Bot API — Making requests, setWebhook, WebhookInfo, Using a Local Bot API Server](https://core.telegram.org/bots/api). Checked 3 December 2026.
2. [Telegram — Marvin's Marvellous Guide to All Things Webhook](https://core.telegram.org/bots/webhooks). Checked 3 December 2026.
3. [Telegram — Bots FAQ](https://core.telegram.org/bots/faq). Checked 3 December 2026.
4. [Telegram Bot API server source — telegram-bot-api/Client.cpp](https://raw.githubusercontent.com/tdlib/telegram-bot-api/master/telegram-bot-api/Client.cpp). Checked 3 December 2026.
5. [Telegram Bot API server source — telegram-bot-api/WebhookActor.cpp](https://raw.githubusercontent.com/tdlib/telegram-bot-api/master/telegram-bot-api/WebhookActor.cpp). Checked 3 December 2026.
6. [telegram-bot-api commit b005f42 — Improve error messages (December 2022)](https://github.com/tdlib/telegram-bot-api/commit/b005f42b2e7bfda030493de804d7171eaeb46898). Checked 3 December 2026.
7. [TDLib source — tdutils/td/utils/port/IPAddress.cpp](https://raw.githubusercontent.com/tdlib/td/master/tdutils/td/utils/port/IPAddress.cpp). Checked 3 December 2026.
8. [TDLib source — tdutils/td/utils/HttpUrl.cpp](https://raw.githubusercontent.com/tdlib/td/master/tdutils/td/utils/HttpUrl.cpp). Checked 3 December 2026.
9. [TDLib source — tdnet/td/net/GetHostByNameActor.h](https://raw.githubusercontent.com/tdlib/td/master/tdnet/td/net/GetHostByNameActor.h). Checked 3 December 2026.
10. [Telegram Bot API server source — telegram-bot-api/telegram-bot-api.cpp](https://raw.githubusercontent.com/tdlib/telegram-bot-api/master/telegram-bot-api/telegram-bot-api.cpp). Checked 3 December 2026.
11. [TDLib source — tdnet/td/net/SslCtx.cpp](https://raw.githubusercontent.com/tdlib/td/master/tdnet/td/net/SslCtx.cpp). Checked 3 December 2026.
12. [TDLib source — tdutils/td/utils/port/SocketFd.cpp](https://raw.githubusercontent.com/tdlib/td/master/tdutils/td/utils/port/SocketFd.cpp). Checked 3 December 2026.
13. [glibc source — sysdeps/posix/gai_strerror-strs.h](https://raw.githubusercontent.com/bminor/glibc/master/sysdeps/posix/gai_strerror-strs.h). Checked 3 December 2026.
14. [aiogram source — aiogram/client/session/base.py](https://raw.githubusercontent.com/aiogram/aiogram/dev-3.x/aiogram/client/session/base.py). Checked 3 December 2026.
15. [aiogram source — aiogram/exceptions.py](https://raw.githubusercontent.com/aiogram/aiogram/dev-3.x/aiogram/exceptions.py). Checked 3 December 2026.
16. [python-telegram-bot source — telegram/error.py](https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/src/telegram/error.py). Checked 3 December 2026.
17. [python-telegram-bot source — telegram/request/_baserequest.py](https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/src/telegram/request/_baserequest.py). Checked 3 December 2026.
18. [Telegram Bot API server source — telegram-bot-api/Client.h](https://raw.githubusercontent.com/tdlib/telegram-bot-api/master/telegram-bot-api/Client.h). Checked 3 December 2026.
