Bad Request: failed to get HTTP URL content — Telegram bot error and how to fix it
Bad Request: failed to get HTTP URL content means your bot sent a photo, document or video as a URL, and Telegram's servers could not download it. The link points at localhost or a private network, needs a login, has expired, or does not answer with the file. Upload the file yourself with multipart/form-data, which aiogram, python-telegram-bot, grammY and Telegraf all support, or give Telegram a public direct link.
By Livops team, the people who build and run LivopsUpdated
The error, as the Telegram Bot API returns it[2]:
{"ok":false,"error_code":400,"description":"Bad Request: failed to get HTTP URL content"}
Each library wraps it in its own words:
| Library | What you see |
|---|---|
| aiogram 3 | TelegramBadRequest: Telegram server says - Bad Request: failed to get HTTP URL content[7][8] |
| python-telegram-bot | telegram.error.BadRequest: Failed to get http url content[10][11] |
| grammY | GrammyError: Call to 'sendPhoto' failed! (400: Bad Request: failed to get HTTP URL content)[14] |
| Telegraf | TelegramError: 400: Bad Request: failed to get HTTP URL content[16] |
python-telegram-bot drops the Bad Request: prefix and runs the rest through Python’s capitalize(), which also lowercases HTTP URL[10]; search your logs case-insensitively. This page explains who downloads the URL and why it fails there, the URL rules Telegram sets, and the fixes in aiogram, python-telegram-bot, grammY and Telegraf, ending with how to give Telegram a working link on Livops.
What does the error mean?
sendPhoto, sendDocument, sendVideo and the other send methods take a file in three ways: a file_id of a file already on Telegram’s servers, an HTTP URL for Telegram to download, or a new file uploaded with multipart/form-data[1]. With a URL, “Telegram will download and send the file”[1]: the Bot API server passes your string on as a remote file[2], a string with a dot in it is read as a URL[5], and for a photo TDLib hands Telegram the URL itself, as an external photo[4]. Your bot never touches the file. Telegram’s servers fetch it, from wherever they are, with none of your bot’s cookies, headers or network access.
When that fetch fails, Telegram answers WEBPAGE_CURL_FAILED, which its API reference describes as a failure while fetching the webpage with cURL[3]. The Bot API server translates it into Failed to get HTTP URL content, lowercases the first letter and puts Bad Request: in front[2]. The message says the download failed, not why: it is a fixed text, with no HTTP status or network error in it[2].
The same family, different messages
All of these come from the same three-way choice of file_id, URL or upload:
| Message | Where it comes from |
|---|---|
failed to get HTTP URL content |
Telegram’s WEBPAGE_CURL_FAILED: fetching the URL failed[2][3] |
wrong type of the web page content |
Telegram’s WEBPAGE_MEDIA_EMPTY, “Webpage media empty”: something was fetched, but it is not media Telegram can send[2][3] |
wrong HTTP URL specified |
Telegram’s EXTERNAL_URL_INVALID (“External URL invalid”) or WC_CONVERT_URL_INVALID[2][3] |
invalid file HTTP URL specified: ... |
TDLib could not parse the string as a URL at all; the reason follows the colon[5] |
can't upload file by URL |
The Bot API server’s wording for a TDLib error, File generation failed[2] |
wrong file identifier/HTTP URL specified |
Telegram reported empty media, for a file_id or a URL alike[6]; see its own page |
A broken file_id never gives failed to get HTTP URL content: a string without a dot is decoded as a file_id, not fetched[5]. If you see this message, Telegram was trying to download a link.
Causes, most common first
1. The link is not on the public internet
Telegram’s servers can reach only what the whole internet can reach. These all work from your laptop or your server and fail for Telegram:
http://localhost:8000/media/photo.jpg,http://127.0.0.1/..., or the bot’s own development server;- a private address such as
10.x.x.x,172.16.x.xto172.31.x.xor192.168.x.x, or a hostname that exists only inside your Docker network or office; - a server behind a VPN, or a firewall that lets in only your own IP addresses.
Fix: upload the file instead (below). Serving it over HTTP just so Telegram can download it adds a public endpoint you do not need.
2. The link needs a login
The file is behind a session cookie, an Authorization header, basic auth, or a token your bot would add. Telegram sends none of them, so the server answers with a login page or an error instead of the file.
Fix: download it in the bot, where you can send the header, and upload it. aiogram’s URLInputFile takes headers for exactly this[9].
3. The signed link has expired
A presigned link to an object in S3 or a compatible storage “remains valid for a limited period of time which is specified when the URL is generated”[18]. A bot that builds the link early — when it queues the message, or once at start — and sends it later can pass Telegram a link that no longer works. Fix: generate the link right before the send call, with an expiry of a few minutes rather than seconds, or upload the object’s bytes.
4. The server answers, but not with the file
A share page of a cloud drive, a link shortener’s preview, a “click to download” page or a bot-check page answers 200 with HTML. Telegram wants the file itself, with the correct MIME type: for example audio/mpeg for sendAudio[1]. Depending on what Telegram got, this ends in this error or in wrong type of the web page content[2][3].
Fix: use the direct file link, and check what it really returns (see How to check a URL).
5. The file or the method does not fit the URL rules
Sending by URL has its own rules, stricter than uploading[1]:
| Rule | By URL | Uploaded |
|---|---|---|
| Photo size | 5 MB at most | 10 MB at most |
| Other files | 20 MB at most | 50 MB at most |
sendDocument |
currently only .PDF and .ZIP files |
any file |
sendVoice |
audio/ogg, no more than 1 MB; 1–20 MB voice notes are sent as files |
— |
sendVideoNote, live photos |
not supported by URL | supported |
thumbnail |
ignored unless the file itself is uploaded | JPEG under 200 kB, at most 320 px a side |
Telegram adds that other configurations may work, but it can’t guarantee that they will[1]. The documentation gives the limits but not the error each one produces, so when a URL fails, check its size and type before anything else. A photo that downloads fine can still be refused for its shape: see PHOTO_INVALID_DIMENSIONS. For files above the upload limits, see file is too big.
6. Redirects, hotlink protection, a slow server
The Bot API documentation does not say whether Telegram follows redirects, which User-Agent it sends, or how long it waits for an answer. So treat each as a risk: a link that redirects through a tracker or a login, a site that serves images only to its own pages or to browsers, and a server that takes a long time to start sending can each fail for Telegram while working in a browser. Fix: a direct link that answers 200 at once, or an upload.
How to fix it
Upload the file instead of sending the link
This works for every cause above, because the bot does the download, with its own headers and network, and Telegram receives the bytes. The upload limits apply: 10 MB for photos, 50 MB for other files[1].
aiogram 3. URLInputFile streams the URL through the bot’s own HTTP session, with optional headers and a timeout that defaults to 30 seconds, and fails on an HTTP error status[9]. Files the bot already has go up with FSInputFile or BufferedInputFile[9]:
from aiogram.types import FSInputFile, URLInputFile
await bot.send_photo(chat_id, URLInputFile(image_url, filename="photo.jpg"))
await bot.send_document(
chat_id,
URLInputFile(report_url, headers={"Authorization": f"Bearer {api_token}"}, filename="report.xlsx"),
)
await bot.send_document(chat_id, FSInputFile("/tmp/report.pdf"))
python-telegram-bot. A string that is not a local file path is sent to Telegram unchanged, as a URL; bytes and open files are uploaded[12]. So download the bytes yourself. httpx is already a dependency of python-telegram-bot[13]:
import httpx
async with httpx.AsyncClient(timeout=30, follow_redirects=True) as client:
response = await client.get(image_url)
response.raise_for_status()
await context.bot.send_photo(chat_id=chat_id, photo=response.content)
grammY. An InputFile built from a URL object is fetched by grammY and uploaded; a failed download throws Download failed, received HTTP status ... in your code, which tells you the status Telegram never would[15]:
import { InputFile } from "grammy";
await ctx.replyWithPhoto(new InputFile(new URL(imageUrl)));
Telegraf 4. Input.fromURL only passes the string to Telegram, which downloads it; Input.fromURLStream streams the URL through your bot instead[17]:
import { Input } from "telegraf";
await ctx.replyWithPhoto(Input.fromURLStream(imageUrl, "photo.jpg"));
curl, for testing with the raw Bot API:
curl -s "https://api.telegram.org/bot$BOT_TOKEN/sendPhoto" \
-F "chat_id=$CHAT_ID" \
-F "[email protected]"
Then send by file_id
The Message that comes back holds the file’s file_id. Save it: sending by file_id has no size limit and needs no download at all[1]. A file_id works only for the bot that received it[1]; if a saved one fails, see wrong file identifier/HTTP URL specified.
Fall back to an upload only when the URL fails
If most of your links work and you want to keep sending them by URL, catch this family and upload instead. In aiogram:
from aiogram.exceptions import TelegramBadRequest
from aiogram.types import URLInputFile
URL_ERRORS = ("failed to get http url content", "wrong type of the web page content")
try:
msg = await bot.send_photo(chat_id, image_url)
except TelegramBadRequest as e:
if not any(text in e.message.lower() for text in URL_ERRORS):
raise
msg = await bot.send_photo(chat_id, URLInputFile(image_url))
aiogram puts Telegram’s description in e.message[7][8]. In grammY compare e.description of a GrammyError[14], in Telegraf e.description of a TelegramError[16], and in python-telegram-bot e.message.lower() of a BadRequest[10]. If the upload fails too, the error is then about the file itself, with your own library’s message instead of Telegram’s.
Or give Telegram a link it can use
If you want Telegram to fetch the file — a public image on your site, a CDN — make sure the link is one it can download.
How to check a URL before you send it
Run this from a machine outside your network, not from the bot’s own server:
curl -sS -o /dev/null -w "%{http_code} %{content_type} %{size_download} bytes %{time_total}s\n" "$FILE_URL"
What you want to see:
200, with no login: not302to a login page,401,403or404;- the file’s own
Content-Type—image/jpeg,image/png,video/mp4,application/pdf— nottext/html; - a size within the URL limits: 5 MB for a photo, 20 MB for anything else[1];
- an answer in a second or two, not a long wait.
Then send it once by hand with the same token the bot uses:
curl -s "https://api.telegram.org/bot$BOT_TOKEN/sendPhoto" \
--data-urlencode "chat_id=$CHAT_ID" \
--data-urlencode "photo=$FILE_URL"
"ok":true means the link is fine, and the bot is sending something else: log the exact URL it passes. The same error means the link is the problem: upload instead.
A Local Bot API Server changes the upload side, not this one: it lets the bot upload files up to 2000 MB, and by a local path with the file URI scheme[1]. A URL is still something to be downloaded.
On Livops
-
Files on the bot’s own disk. A file the bot made — a chart, a PDF report, a resized photo — is already where the bot can upload it: write it to
/tmp, which is wiped on every restart and deploy and holds 128 MB, or to/app/data(its path is inDATA_DIR), which is kept across deploys. Upload it from there withFSInputFileor its equivalent; do not serve it over HTTP for Telegram. -
No address to serve it from. A
botservice needs no public URL and aworkerhas none, so a link to a file inside them, or tolocalhost, is not one Telegram can open. Databases are reachable only from inside the project, by internal names such aspostgres. -
Storage buckets. A storage bucket is private by default and gives temporary signed links (presigned URLs); generate one right before each send. The whole bucket can be made public instead: a
..._PUBLIC_URLvariable is then added, and URLs are path-style,https://s3.livops.app/<bucket>/<file>. Either way, Telegram needs no login, and the URL limits above still apply. -
The right Content-Type. When the bot uploads a file to the bucket with
boto3, passContentTypeinExtraArgs[19][20], then check the link with thecurlline above:import os, boto3 s3 = boto3.client("s3", endpoint_url=os.environ["S3_ENDPOINT"]) s3.upload_file("chart.png", os.environ["S3_BUCKET"], "charts/chart.png", ExtraArgs={"ContentType": "image/png"}) url = s3.generate_presigned_url( "get_object", Params={"Bucket": os.environ["S3_BUCKET"], "Key": "charts/chart.png"}, ExpiresIn=600 ) -
Logs. Log the URL next to each failed send. The project’s Logs page shows the error line, and
livops logs <service> -ffollows it from the terminal; see CLI.
A bot costs 19 credits a month (19,000 so’m), and one 1 GB storage bucket per team is free; see Pricing and Files and data.
Questions
Why does the link open in my browser but Telegram cannot get it?
Your browser is not the one downloading it. With a URL, Telegram's servers fetch the file over the internet, without your cookies, your login, your VPN or your local network. A link to localhost, a private IP address, a page behind a login or a signed link that has expired works for you and fails for them.
What are the size limits when sending a file by URL?
5 MB for photos and 20 MB for other types of content. Uploading the file yourself with multipart/form-data allows 10 MB for photos and 50 MB for other files, and resending by file_id has no limit.
How do I send a file Telegram cannot download?
Download it in your bot and upload it. aiogram's URLInputFile and grammY's InputFile with a URL object do that in one line, Telegraf has Input.fromURLStream, and in python-telegram-bot you download the bytes, for example with httpx, and pass them as the photo or document.
What is the difference between failed to get HTTP URL content and wrong type of the web page content?
In the Bot API server's source the first is Telegram's WEBPAGE_CURL_FAILED, a failure while fetching the URL. The second is WEBPAGE_MEDIA_EMPTY: Telegram fetched something, but it was not media it could send. Both are fixed the same way: a direct public link with the file's own Content-Type, or an upload.
Can I send a document of any type by URL?
No. The Bot API says sending by URL in sendDocument currently works only for PDF and ZIP files, the file must have the correct MIME type, and video notes and live photos cannot be sent by URL at all. For other files, upload them.
Should I retry the same URL?
Once at most, if the server behind it may have been slow or briefly down. If it fails again, the link itself is the problem: upload the file instead, and save the file_id Telegram returns so the next sends need no URL at all.
Sources
- Telegram Bot API — Making requests, Sending files, sendPhoto, sendVideoNote, Using a Local Bot API Server (core.telegram.org). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
- Telegram API — messages.sendMedia (possible errors) (core.telegram.org). Checked .
- TDLib source — td/telegram/Photo.cpp (raw.githubusercontent.com). Checked .
- TDLib source — td/telegram/files/FileManager.cpp (raw.githubusercontent.com). Checked .
- TDLib source — td/telegram/MessageQueryManager.cpp (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/types/input_file.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 .
- python-telegram-bot source — telegram/_utils/files.py (raw.githubusercontent.com). Checked .
- PyPI — python-telegram-bot (pypi.org). Checked .
- grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
- grammY source — src/types.node.ts (raw.githubusercontent.com). Checked .
- Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .
- Telegraf 4.16.3 source — src/input.ts (github.com). Checked .
- Boto3 docs — Presigned URLs (docs.aws.amazon.com). Checked .
- Boto3 docs — Uploading files (ExtraArgs) (docs.aws.amazon.com). Checked .
- s3transfer source — s3transfer/manager.py (ALLOWED_UPLOAD_ARGS) (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- Telegram 400: Bad Request: wrong file identifier/HTTP URL specified — how to fix itBad Request: wrong file identifier/HTTP URL specified means Telegram could not use the file you passed as a photo, document or other media. Usually the file_id belongs to a different bot (a file_id works only for the bot that got it), a file_unique_id was sent instead, the id was cut, or Telegram could not download your URL. Upload the file again with this bot and save the new file_id, or upload it instead of sending a link.
- Bad Request: file is too big — Telegram bot file size limits and how to get around themBad Request: file is too big means the bot called getFile for a file over the Bot API's 20 MB download limit. Request Entity Too Large (413) is the upload side: a file uploaded over the 50 MB limit. Resend by file_id, which has no limit, compress or split the file, or run a Local Bot API Server, which downloads without a size limit and uploads up to 2000 MB.
- Bad Request: PHOTO_INVALID_DIMENSIONS — Telegram sendPhoto size rules and the fixBad Request: PHOTO_INVALID_DIMENSIONS means Telegram would not take the image as a photo because of its shape or size: for sendPhoto, width plus height must not exceed 10000 pixels and the longer side may be at most 20 times the shorter. Long screenshots, receipts and panoramas break these rules. Resize or pad the image with Pillow, split a tall one into an album, or send the original file with sendDocument.
- 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.
- Is the Telegram Bot API free? Limits and costs in 2026Yes. Telegram charges nothing to create a bot or to call the Bot API, and bots message their users at no cost. What costs money is around it: the server the bot runs on, paid broadcasts above about 30 messages a second, and Telegram Stars when you sell digital goods. The free API has limits: about one message a second per chat, 20 a minute per group, 20 MB downloads and 50 MB uploads, more with a local Bot API server.
- 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).
- grammY bot deploy: polling, webhooks and hostingDeploy a grammY bot as one always-on Node.js process: bot.start() for polling, or webhookCallback() behind an HTTP server, with bot.stop() on SIGTERM. On Livops a repository with grammy in package.json runs as a bot from every push, for 19 credits a month (19,000 so'm).
- Telegraf bot hosting: deploying a Telegraf 4 bot on Node.jsA Telegraf bot is one Node.js process: bot.launch() for polling, or bot.webhookCallback() behind an HTTP server for a webhook, with bot.stop() on SIGTERM. On Livops a repository with telegraf in package.json is run as a bot from every push, for 19 credits a month (19,000 so'm).