send more than 1 image with twilio and flask


hi i’m new in flask and twilio, i’m try to send 2 images with 1 request but just appears the last image that i put in the array

this is my code

from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from import Client
from dotenv import load_dotenv
import os


app = Flask(__name__)

def hello():
    return "Hello, World!"

@app.route("/sms", methods=['POST'])
def sms_reply():
    """Respond to incoming calls with a simple text message."""
    # Fetch the message
    msg = request.form.get('Body')

    # CLIENT 
    client = Client(os.getenv("TWILIO_ID"), os.getenv("AUTH_TOKEN"))
    number = request.values.get('From', '')
    #  creating the message
    if msg == "imagen":
        message = client.messages.create(
                                media_url=["", ""],
        resp = MessagingResponse()
        resp.message("imagen : {}".format(message.body))
        return str(resp)

how could see in the "media_url" parameter i put 2 urls, but twilio just send my 1, i made a mistake?. i try it in this way too

        mss = MessagingResponse()
        resp = mss.message("this is a message")
        return str(resp)

but is the same. thnks for ur help


Twilio developer evangelist here. That code should work, it’s just that there is no bunny image at that URL. You will need your image to be hosted at a publicly-accessible URL like these:

 message = client.messages.create(
     body="Test sending two messages",
     media_url=["", ""],

That returns this image:
sms example received
I’d recommend using Twilio Runtime Assets, our static file hosting service that allows developers to quickly upload and serve the files needed to support their applications. host your files that support web, voice, and messaging applications. Assets is commonly used to host .mp3 audio files used in TwiML, to serve images sent through MMSes, or store configuration used by Twilio Functions. You can also deploy the images to be hosted on web servers.

Let me know if this helps at all!

Answered By – lizziepika

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published