I am sending photos by url in my Telegram bot. For some photos, I am getting an error from Telegram:
{"ok":false,"error_code":400,"description":"Bad Request: wrong file identifier/HTTP URL specified"}
For example: sending this photo works:
https://api.telegram.org/bot<BOT_KEY>/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 file strangely doesn't work:
https://api.telegram.org/bot<BOT_KEY>/sendPhoto?chat_id=<CHAT_ID>&photo=https%3A%2F%2Fdrscdn.500px.org%2Fphoto%2F247611167%2Fq%253D80_m%253D1500%2Fv2%3Fwebp%3Dtrue%26sig%3Dcfa117f225962250323c1202797abe8d45b47d59da12d780f4bf5231687c4331
Notice that, for both examples:
Am I doing something wrong? Or any idea about the problem?
Thanks,
Possible solution:
Add useless attribute with random value to file url and retry until it successes.
I encountered this problem, too. I just found that nearly same files with nearly same urls have different behaviors. It shocked me. I don't think it's my files' fault, so I modified the file url by adding an useless attribute and tuning its value. After retrying many times, it worked!
You can have a try by running this snippet. The only differences are &random=58
and &random=64
at the end of each file url.
<h5>Your Bot Token</h5>
<input id="token" type="text" style="width: 400px;" value="{YourBotToken}" />
<h3>200 OK Example</h3>
<form action="https://api.telegram.org/bot{YourBotToken}/sendPhoto" method="POST" enctype="application/x-www-form-urlencoded">
<textarea type="text/html" name="photo" rows="4" cols="70" readonly="readonly">http://api.map.baidu.com/staticimage?center=140.50,36.15&width=1024&height=576&zoom=6&copyright=1&markers=140.50,36.15&markerStyles=l&random=58</textarea>
<input type="text" name="chat_id" value="@{YourChatID}" />
<input type="submit" value="Submit" onclick="this.form.action='https://api.telegram.org/bot'+document.getElementById('token').value+'/sendPhoto';" />
</form>
<br><br>
<h3>400 Bad Request Example</h3>
<form action="https://api.telegram.org/bot{YourBotToken}/sendPhoto" method="POST" enctype="application/x-www-form-urlencoded">
<textarea type="text/html" name="photo" rows="4" cols="70" readonly="readonly">http://api.map.baidu.com/staticimage?center=140.50,36.15&width=1024&height=576&zoom=6&copyright=1&markers=140.50,36.15&markerStyles=l&random=64</textarea>
<input type="text" name="chat_id" value="@{YourChatID}" />
<input type="submit" value="Submit" onclick="this.form.action='https://api.telegram.org/bot'+document.getElementById('token').value+'/sendPhoto';" />
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With