Note that there are some explanatory texts on larger screens.

plurals
  1. POPython date time comparison with None value (Landscape API)
    primarykey
    data
    text
    <p>I am cutting some data from web service one of parameters is last_ping_time witch can be at some point None value. I am comparing current date with last_ping_time to check communication with machine. So I get</p> <p><em>ValueError: time data 'None' does not match format '%Y-%m-%dT%H:%M:%SZ'</em></p> <p>I tried to set dummy value if I get None</p> <pre><code> if ping=="None": ping="2013-01-01T00:00:00 </code></pre> <p>Tried also break or continue nut they don't seem to work this error persists. I need loop continue to next value if null or put some dummy value and also continue. I am out of ideas, please help. </p> <pre><code>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&lt;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)) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload