Twilio python MessagingResponse.message.media 不适用于 mp3 音频

Twilio python MessagingResponse.message.media not working for a mp3 audio

@app.route('/bot', methods=['POST'])
def bot():

    content = request.form.get('Body').lower()

    resp = MessagingResponse()
    msg = resp.message()

    responded = False

    if 'hi' in content:
        msg.media(url_for('static', filename='bonjour.mp3'), content_type='audio/mpeg')
        responded = True
    if not responded:
        msg.body('no')
    return str(resp)

这是我回复 Whatsapp 消息的代码。如果你说 'hi',它应该会向你发送我保存的 mp3 音频(我检查过路径是否正确),如果你说别的,它只会说 'no'。但是当我使用 'hi' 发送消息时,我在 Twilio 调试部分收到此错误: error 12200

您传递给 media() 的 URL 需要是公开可用的媒体文件的绝对 URL,而不是相对文件。

你的情况不是 /static/bonjour.mp3,而是 https://yourdomain.com/static/bonjour.mp3

同时省略content_type