You are about to send a POST request to https://api.telegram.org/bot~~~/sendaudio to send a file to the Telegram bot.
URL = 'https://api.telegram.org/bot<...>/sendaudio'
VALUE = {'chat_id': '<...>'}
FILE = {'audio': open('a.mp3', 'rb')}
r = requests.post(URL, data=VALUE, files=FILE)
If you do this, the file will be transferred normally and the server will respond.
By the way, the file name is
FILE = {'audio': open('あ.mp3', 'rb')} or FILE = {'audio': open('ga.mp3', 'rb')}
If you do this and do the same, the server responds that it has not received the audio. It seems to be an error that occurs in the process of using requests because it works normally if it is sent through Postman, so how can I solve it? ㅠ 다른 Or is there any other way to implement the same functionality?
python requests
Please use the open function of the codecs module below.
import codecs
codecs.open(u'hangeul file name).mp3', 'rb')
Using Python 3.5.3 version...
>>> FILE = {u'audio': codecs.open(u'hi).mp3', 'rb')}
>>> r = requests.post(URL, data=VALUE, files=FILE)
>>> r
<Response [413]>
>>> r = requests.post(URL, data=VALUE, files=FILE)
>>> r
<Response [400]>
>>> r = requests.post(URL, data=VALUE, files=FILE)
>>> r
<Response [400]>
>>> r
<Response [400]>
>>> FILE = {u'audio': codecs.open(u'hi.mp3', 'rb')}
>>> r = requests.post(URL, data=VALUE, files=FILE)
>>> r
<Response [413]>
>>> r = requests.post(URL, data=VALUE, files=FILE)
>>> r
<Response [400]>
>>> r = requests.post(URL, data=VALUE, files=FILE)
>>> r
<Response [400]>
After checking it again and trying several times, the first request sent after creating a file object in this way returns 413 responses, but the rest returns to 400. 텔레ㅠ I think there is a problem with the Telegram server side... I don't know... (Crying)
© 2024 OneMinuteCode. All rights reserved.