Issue with sending images through URL in my Telegram bot
I’m working on a Telegram bot that sends images using URLs. Most of the time it works fine, but sometimes I get this error response:
{"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}
Here’s what’s confusing me. I have two similar image URLs from the same domain:
This one works perfectly:
https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<CHAT_ID>&photo=https%3A%2F%2Fdrscdn.500px.org%2Fphoto%2F153590277%2Fq%253D80_m%253D2000%2Fv2%3Fwebp%3Dtrue%26sig%3D8b429a27872dfdb4f68ddc5edd488ce9e6a57977415fa323178cd62c5100a3ff
But this one fails with the error:
https://api.telegram.org/bot<TOKEN>/sendPhoto?chat_id=<CHAT_ID>&photo=https%3A%2F%2Fdrscdn.500px.org%2Fphoto%2F247611167%2Fq%253D80_m%253D1500%2Fv2%3Fwebp%3Dtrue%26sig%3Dcfa117f225962250323c1202797abe8d45b47d59da12d780f4bf5231687c4331
Both URLs have these characteristics:
- They’re accessible and valid
- Same file format (JPEG)
- Under the 10MB size limit
- From the same image hosting service
What could be causing this inconsistent behavior? Is there something specific about certain URLs that Telegram doesn’t accept?
I’ve hit this exact problem before - super frustrating. Usually it’s URL encoding conflicts or Telegram’s servers acting up. A retry mechanism with exponential backoff saved me - the same URL that fails will often work seconds later. What also worked was downloading the image to my server first, then uploading it as a file instead of using the URL parameter. Extra step, but way more reliable. Also check for hidden special characters or weird parameters in the failing URLs. They might look identical but could be breaking Telegram’s parser.
Had the same issue with CDN image URLs. It’s usually double URL encoding - your working URL has q%253D80 but the failing one gets processed differently by Telegram’s backend. I switched to POST with multipart/form-data instead of GET parameters and that fixed it. The photo parameter handles complex URLs way better in the request body than the query string. Also check if your failing URL has proper HTTP headers - some CDNs serve images with missing or wrong Content-Type headers that Telegram rejects even though browsers show them fine.
Yeah, I’ve hit this before. Telegram’s CDN sometimes can’t reach certain URLs even from the same domain - usually temporary server issues on 500px’s end or weird caching. Try adding a random query parameter like &t=123456 to force a refresh. Works surprisingly often.