0
當我運行一個Python客戶端插入數據到具有特定時間戳的InfluxDb時,它返回這個錯誤:'datetime.timedelta'對象有沒有屬性'total_seconds'。 我在github上發現了一些將total_seconds()
方法定義爲timeutils.py
文件的方法。這裏是代碼:用Python插入InfluxDb錯誤:'datetime.timedelta'對象沒有屬性'total_seconds'
from datetime import datetime
def total_seconds(td):
# Keep backward compatibility with Python 2.6 which doesn't have
# this method
if hasattr(td, 'total_seconds'):
return td.total_seconds()
else:
return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6)/10**6
def convert_to_epoch(timestamp):
diff = (timestamp - datetime(1970, 1, 1))
seconds = int(diff.total_seconds())
seconds = int(total_seconds(diff))
return seconds
我找不到timeutils.py。 Python版本是2.6,我不能更新到2.7。我應該在哪裏添加該功能以使客戶端工作?
謝謝!有用。 – Caramelleamare