Python时间作为价值

时间:2017-04-26 20:10:25

标签: python datetime suds

我正在尝试使用hp nnmi网络服务。但是在这里你可以看到我在filter2.value = d_in_ms中使用毫秒作为值,这对我不起作用。当我使用像filter2.value = "1493078400000"这样的值时,我能够看到结果。请告诉我是否可以使用如下所示的int值:

#!/usr/bin/python

from suds.client import Client
from suds.transport.http import HttpAuthenticated

import datetime
import time
now = datetime.datetime.now()
currenttime = now - datetime.timedelta(hours=12)
epochtime = time.mktime(currenttime.timetuple())
print epochtime
d_in_ms = int(epochtime)*1000

t = HttpAuthenticated(username='xxxxx', password='xxxx')

url = 'http://example.com/IncidentBeanService/IncidentBean?wsdl'

client = Client(url, transport=t)
filter1 = client.factory.create('ns2:condition')
filter1.name = "sourceNodeName"
filter1.operator = "EQ"
filter1.value = "DEVICE"

filter2 = client.factory.create('ns2:condition')
filter2.name = "lastOccurrenceTime"
filter2.operator = "GT"
filter2.value  = d_in_ms


filter = client.factory.create('ns2:expression')
filter.operator = "AND"
filter.subFilters = [filter1, filter2]

allincidents = client.service.getIncidents(filter)
print "Nodes in topology:", len(allincidents.item)

for i in allincidents.item[:]:
  print i

1 个答案:

答案 0 :(得分:0)

  

当我使用像filter2.value =" 1493078400000"

这样的值时,我能够看到结果

根据此声明,它看起来filter2.value应该是一个字符串。这表明您需要使用:

filter2.value = str(d_in_ms)