我正在嘗試在給定日期之前從 twilio 消息列表中檢索 SMS 消息。當(dāng)我用等號詢問給定日期時,它會起作用(它會在 2019 年 2 月 2 日返回所有短信: timestamp = datetime.datetime(2019, 2, 15, 0, 0,0) client = Client(account_sid, auth_token) messages = client.messages.list( date_sent=timestamp )但如果我嘗試使用: date_sent<=timestamp或者 date_sent>=timestamp我收到一個錯誤。global name 'date_sent' is not defined文檔似乎建議您可以使用 >= 或 <= 運算符,但這種方式在實踐中不起作用。任何想法如何讓它吐出正確的數(shù)據(jù)?
1 回答

Cats萌萌
TA貢獻1805條經(jīng)驗 獲得超9個贊
Twilio 開發(fā)者布道者在這里!很好的問題,這沒有很好的記錄。我會和團隊一起解決這個問題。
python庫在日期之前有一個不同的過濾器參數(shù),所以你需要的是date_sent_before而不是date_sent:
import os
import datetime
from twilio.rest import Client
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
timestamp = datetime(2019, 2, 15, 0, 0,0)
client = Client(account_sid, auth_token)
# retrieve all messages before a given date
messages = client.messages.list(date_sent_before=timestamp)
print(len(messages1))
print(len(messages2))
如果您有任何其他問題,請告訴我 :)
添加回答
舉報
0/150
提交
取消