I want to send a file with the post method, but I don't know what's wrong with my code I have chat_id, file_id, and every requirement parameters this is a sample code for sending voice via POST Request
import requests
my_data = {'chat_id': '72600457' ,'file_id': 'AwADBAADPAYAAvFWCVFZFfPyZdGLfhYE'}
my_url = 'https://api.telegram.org/bot<MY TOKEN>/sendVoice'
request.post(url=my_url, data=my_data)
when I run the code, no error happens. But nothing is shown from the bot; This file_id works with GET METHOD and I could send text with POST METHOD, But for files it seems it doesn't work.
Check documentation for sendVoice - it doesn't use name file_id
but voice
data = {'chat_id': '72600457', 'voice': 'AwADBAADPAYAAvFWCVFZFfPyZdGLfhYE'}
If you use file ID then you can use POST
but also GET
And you should get response from server to see information about wrong request
import requests
token = '<MY TOKEN>'
data = {'chat_id': '72600457', 'voice': 'AwADBAADPAYAAvFWCVFZFfPyZdGLfhYE'}
url = f'https://api.telegram.org/bot{token}/sendVoice'
#response = requests.post(url, data=data)
response = requests.get(url, params=data)
print(response.json())
By the way: there is module python-telegram-bot . GitHub: python-telegram-bot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.