尝试使用请求库Python发送视频时出错

2024-09-19 23:35:38 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试发布视频文件时遇到错误代码:400。你知道吗

错误

400 Bad Request
b'{
    "ok":false,
    "error_code":400,
    "description":"Bad Request: there is no video in the request"
}'

请告知问题所在(视频文件工作并存在于所述路径中)

def sendVideo(bot_token,bot_chatID):
    url = "https://api.telegram.org/bot"+ bot_token +"/sendVideo";
    files = {'file': open('C:/Users/myUser/Desktop/telegram/t_video.mp4', 'rb')}
    data = {'chat_id' : bot_chatID}
    r = requests.post(url, files=files)
    print(r.status_code, r.reason, r.content)

Tags: tokenurlrequestvideobot错误codeok
1条回答
网友
1楼 · 发布于 2024-09-19 23:35:38

改变一下这个

files = {'file': open('C:/Users/myUser/Desktop/telegram/t_video.mp4', 'rb')}

为了这个

files = {'video': open('C:/Users/myUser/Desktop/telegram/t_video.mp4', 'rb')}

因为Bot API需要video参数名来确定媒体的类型。你知道吗


你忘了把data=data(或params=data)加到requests.post()来传递chat_id。你知道吗

相关问题 更多 >