AttributeError: 'MessagingResponse' object has no attribute 'media'
zhouhao27 opened this issue · comments
Issue Summary
Got the following error message when I tried to attach an image url to a message:
AttributeError: 'MessagingResponse' object has no attribute 'media'
Steps to Reproduce
- Just run the application
- Send a message through WhatsApp
Code Snippet
def reply():
incoming_que = request.values.get('Body', '').lower()
print("Question: ", incoming_que)
answer = "Your input is: {}".format(incoming_que)
print("BOT Answer: ", answer)
bot_resp = MessagingResponse()
msg = bot_resp.message(answer)
msg.media("https://samplelib.com/lib/preview/png/sample-boat-400x300.png")
return str(bot_resp)
If I comment out the line of msg.media
, everything's fine.
Exception/Log
Question: h
BOT Answer: Your input is: h
[2023-05-12 10:12:17,219] ERROR in app: Exception on /reply [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.10/dist-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/root/whatsapp-bot/app.py", line 45, in reply
msg.media("https://samplelib.com/lib/preview/png/sample-boat-400x300.png")
AttributeError: 'MessagingResponse' object has no attribute 'media'
127.0.0.1 - - [12/May/2023 10:12:17] "POST /reply HTTP/1.0" 500 -
Technical details:
- twilio-python version: 6.0.0
- python version: 3.10.6
Hi @zhouhao27, Thanks for the heads up!
I tried reproducing this issue, by creating a variable of MessagingResponse and adding a media (with the same url provided in your example) to its message. This is working with the latest version of twilio-python. Can you please try this with the latest version?
@AsabuHere Thanks for your reply. What is the latest version? How can I install the latest version in pip?
It's working for Twilio 8.0.0. Thanks. Close.