File size: 51.2 KB Trying to send:
>>> send_img_url = 'https://api.telegram.org/botXXXXXXXXXXXXXXXXXXXXX/sendPhoto'
>>> img_name = 'C:/Users/Administrator/Downloads/WhatsApp Image 2019-05-30 at 20.54.40.jpeg'
>>> r = requests.post(send_img_url, data={'chat_id': '-351543550', 'photo': open(img_name, 'rb')})
>>> r
<Response [413]>
>>> r.reason
'Request Entity Too Large'
>>> r.content
b''
>>>
Also i try some another requests like:
photo = open(('C:/Users/Administrator/Downloads/WhatsAppImage.jpeg').encode('utf-8'), 'rb')
r = requests.post(send_img_url, data={'chat_id': '-351543550', 'photo': photo})
and:
with io.open('C:/Users/Administrator/Downloads/WhatsAppImage.jpeg', encoding='utf-8', errors='ignore') as f:
r = requests.post(send_img_url, data={'chat_id': '-351543550', 'photo': f})
Last option give me next error:
>>> r
<Response [400]>
>>> r.reason
'Bad Request'
Using a Local Bot API Server you can send a large file up to 2GB.
GitHub Source Code:
https://github.com/tdlib/telegram-bot-api
Official Documentation
https://core.telegram.org/bots/api#using-a-local-bot-api-server
You can build and install this to your server by following the instructions on this link https://tdlib.github.io/telegram-bot-api/build.html
basic setup :
./telegram-bot-api --api-id=<your-app-id> --api-hash=<your-app-hash> --verbosity=20http://127.0.0.1:8081/bot<token>/METHOD_NAME reference: https://core.telegram.org/bots/apiExample Code with:
import requests
url = "http://127.0.0.1:8081/bot<your-bot-token>/sendVideo"
payload={'chat_id': 'chat_id',
'supports_streaming': 'true'}
files=[
('video',('your_file_name.mp4',open('path_of_file','rb'),'application/octet-stream'))
]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
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