Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python无值日期时间比较(横向API)_Python_Api - Fatal编程技术网

Python无值日期时间比较(横向API)

Python无值日期时间比较(横向API),python,api,Python,Api,我正在从web服务中剪切一些数据,其中一个参数是last_ping_time,它在某个时刻可能没有值。我正在将当前日期与上次时间进行比较,以检查与机器的通信。 所以我明白了 ValueError:时间数据“无”与格式“%Y-%m-%dT%H:%m:%SZ”不匹配 如果没有,我尝试设置虚拟值 if ping=="None": ping="2013-01-01T00:00:00 还尝试了断开或继续螺母,但它们似乎不起作用。此错误仍然存在。我需要循环继续到下一个值,如果为null,或者

我正在从web服务中剪切一些数据,其中一个参数是last_ping_time,它在某个时刻可能没有值。我正在将当前日期与上次时间进行比较,以检查与机器的通信。 所以我明白了

ValueError:时间数据“无”与格式“%Y-%m-%dT%H:%m:%SZ”不匹配

如果没有,我尝试设置虚拟值

   if ping=="None":

   ping="2013-01-01T00:00:00
还尝试了断开或继续螺母,但它们似乎不起作用。此错误仍然存在。我需要循环继续到下一个值,如果为null,或者放置一些伪值,然后继续。 我没有主意了,请帮忙

with open(filename, 'wb') as csvfile:   #Creating report file
    spamwriter = csv.writer(csvfile, delimiter='    ')
    for computer in computers:

        ping=computer["last_ping_time"]
        ping=str(ping)
        ping.split('T')
        if ping=="None":
        #break
        ping="2013-01-01T00:00:00"  
        else

                ping=datetime.datetime.strptime(ping, '%Y-%m-%dT%H:%M:%SZ') # Convert string to data

                if ping<Current_Date: 
                        #toremove=count+1
                        os.system('zenity --info --text="Computers not contacting more than 30 days:%s "' % (computer["hostname"]))
                        #print "Needs to be deleted" #Control Variable

                        spamwriter.writerow((computer["id"], computer["hostname"], computer["title"], computer["last_ping_time"], "30 Days from last contact machine will be be removed"))
                else:
                        network=str(computer) #list to string
                        ip=network.split("u'ip_address': u'")[1] #1 shows what is after parameters
                        ip=ip.split("'")[0] #0 shows what is before parameters
                        mac=network.split("u'mac_address': u'")[1]
                        mac=mac.split("'")[0] 
                        print mac
                        print ip
                        spamwriter.writerow((computer["id"], computer["hostname"], computer["title"], computer["last_ping_time"], mac, ip)) 
os.system('zenity --info --text="Report is created with name:%s "' % (filename))
将open(filename,'wb')作为csvfile:#创建报告文件 spamwriter=csv.writer(csvfile,分隔符=“”) 对于计算机中的计算机: ping=计算机[“上次ping”] ping=str(ping) ping.split('T')) 如果ping==“无”: #中断 ping=“2013-01-01T00:00:00” 其他的 ping=datetime.datetime.StrTime(ping,%Y-%m-%dT%H:%m:%SZ')#将字符串转换为数据 如果ping删除
ping=str(ping)
行并使用:

if ping is None:
   # no last ping time