python datatime result a malformed string while using strptime

36 Views Asked by At

[04/10/2024:23:18:39] PUT "/new/origin" HTTP/1.1 200 256

strptime method is resulting fatal during run

1

There are 1 best solutions below

1
Dev On

Try doing this

      ee = re.findall(r'\[(.*?)\]', i)[0]
      '''
      The Strftime() function is used to convert date and time 
      objects to their string representation. It takes one or 
       more inputs of formatted code and returns the string 
      representation 
      '''
      dt = datetime.datetime.strptime(ee, '%d/%m/%Y:%H:%M:%S').strftime('%d/%m/%Y:%H:%M:NN')  
  if date in diversed.keys():
    d_v[date]=diversed[date]+1
    # print(diversed[date])
  else:
    diversed[date]=1
    # print("no duplicates")
print(diversed)