我想获取Twilio SMS日志并以HTML格式打印出来。代码是:
from twilio.rest import TwilioRestClient
@application.route("/logs", methods=['GET', 'POST'])
def logs():
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
data = client.sms.messages.list()
return data
这会返回如下错误:
File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Python/2.7/site-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/Library/Python/2.7/site-packages/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/Library/Python/2.7/site-packages/werkzeug/wrappers.py", line 841, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/Library/Python/2.7/site-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "/Library/Python/2.7/site-packages/werkzeug/test.py", line 867, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'list' object is not callable
" list对象是否不可调用"意味着对象是空的还是其他的?执行此操作的正确方法是什么,并返回一个我可以解析为json的对象?
非常感谢提前。
答案 0 :(得分:1)
data = client.sms.messages.list()
的输出应如下所示:
"page": 0,
"page_size": 50,
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json"
"first_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json?Page=0&PageSize=50",
"next_page_uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json?Page=1&PageSize=50",
"previous_page_uri": null,
"sms_messages": [
{
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"api_version": "2008-08-01",
"body": "A message from StackOverflow.",
"date_created": "Mon, 16 Aug 2010 03:45:01 +0000",
"date_sent": "Mon, 16 Aug 2010 03:45:03 +0000",
"date_updated": "Mon, 16 Aug 2010 03:45:03 +0000",
"direction": "outbound-api",
"from": "+14158141829",
"price": "-0.02000",
"sid": "SM800f449d0399ed014aae2bcc0cc2f2ec",
"status": "sent",
"to": "+14159978453",
"uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM800f449d0399ed014aae2bcc0cc2f2ec.json"
},
...
]
}
查看有关检索日志的FAQ,并告诉我这是否有帮助。