Webサービスからいくつかのデータを切り取っています。パラメーターの1つはlast_ping_timeです。魔女はある時点で値なしになる可能性があります。現在の日付をlast_ping_timeと比較して、マシンとの通信を確認しています。だから私は得る
ValueError:時間データ'なし'が形式'%Y-%m-%dT%H:%M:%SZ'と一致しません
Noneを取得した場合、ダミー値を設定しようとしました
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))