Python 时间作为价值
Python time as value
我正在尝试使用 hp nnmi Web 服务。但是在这里你可以看到我在 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
I am able to see result when I use values like filter2.value = "1493078400000"
按照这个说法,看起来filter2.value
应该是一个字符串。这表明您需要使用:
filter2.value = str(d_in_ms)
我正在尝试使用 hp nnmi Web 服务。但是在这里你可以看到我在 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
I am able to see result when I use values like filter2.value = "1493078400000"
按照这个说法,看起来filter2.value
应该是一个字符串。这表明您需要使用:
filter2.value = str(d_in_ms)