[英]Get message from Twilio REST API throws 'SmsMessages object is not callable'
I am trying to get a message object from the Twilio REST API, and it's not working. 我正在尝试从Twilio REST API获取消息对象,但它不起作用。
I have a class method that creates and sends a sms message with Twilio. 我有一个使用Twilio创建并发送短信的类方法。 It looks something like this:
看起来像这样:
def send_sms(self, recipient, body):
client = twilio.rest.TwilioRestClient(
self._account_sid,
self._auth_token)
try:
message = client.sms.messages.create(
to=recipient,
from_=self._from,
body=body)
except twilio.TwilioRestException as error:
# do some stuff...
return message
I have another class method that is supposed to get the message object from Twilio, so I can check the status: 我还有另一个应该从Twilio获取消息对象的类方法,因此我可以检查状态:
def get_sms(self, sid):
client = twilio.rest.TwilioRestClient(
self._account_sid,
self._auth_token)
message = client.sms.messages(sid).fetch()
return message
Unfortunately, my attempt to get the message using the sid is not working. 不幸的是,我尝试使用sid获取消息不起作用。 The
message = client.sms.messages(sid).fetch()
line method throws an error: TypeError: 'SmsMessages' object is not callable
. message = client.sms.messages(sid).fetch()
行方法引发错误: TypeError: 'SmsMessages' object is not callable
。
This is frustrating, because according to the docs I am doing this correctly. 这令人沮丧,因为根据文档,我正确地做到了这一点。 I have tried removing the
.sms.
我尝试删除
.sms.
from the line also! 从行也!
I was mixing use of the TwilioRestClient
, from the REST API v5.x, with use of fetch()
, from the REST API v6.x. 我正在混合使用REST API v5.x中的
TwilioRestClient
和REST API v6.x中的fetch()
。 For future reference, there is a tiny version toggle button in the top right corner of the code explorer in the Twilio docs! 为了将来参考,Twilio文档中的代码浏览器右上角有一个微小的版本切换按钮!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.