Twilio:“CallInstance”对象没有属性“from_”

问题描述 投票:0回答:1

这可能是我错过的关于 Python 的介绍性内容,但我不知道如何做到这一点。我正在重用一段在过去使用 Twilio Python 库的 Web 应用程序中有效的代码,但它不再有效。

我正在尝试使用 call_sid 检索有关呼叫的一些数据,特别是“来自”号码。

    records = twilioCli.recordings.list(limit=5)
    for rec in records:
        call_sid = rec.call_sid
        abc = twilioCli.calls(call_sid).fetch()
        print(abc)
        print(abc.from_formatted)
        print(abc.from_)

twilioCli
是我的 Twilio 客户端,运行良好(因为我在其他功能中使用它。

print(abc) 给我:

<Twilio.Api.V2010.CallInstance account_sid=[my account sid] sid=[call sid]>

print(abc.from_formatted) 为我提供了我的发件人号码的格式化号码。 print(abc.from_) 给了我:

AttributeError: 'CallInstance' object has no attribute 'from_'

根据 Twilio API 调用资源页面,我应该写

abc.from
而不是
abc.from_
。然而,当我尝试只使用“from”时,它会出现语法错误。假设这只是一个基本的 Python 事情,必须在“from”后面添加下划线来转义它(这可能就是它之前在其他项目中起作用的原因)。想知道我做错了什么吗?

我已将 Twilio Python 库更新为最新更新 (twilio==9.0.5)。谢谢大家!

python flask twilio
1个回答
0
投票

根据我五分钟的谷歌搜索和查看,它看起来像 .from_ 在本例中不存在可以使用的属性,但 .from 确实存在。所以只需 rm _ from print(abc.from_) 这样就可以了

打印(abc.from)

© www.soinside.com 2019 - 2024. All rights reserved.