ValueError: time data '"2015-06-25 14:50:00"' does not match format
'%Y-%m-%d %H:%M:%S'
但我使用的格式是正确的。这是我的代码到代码的各个部分。
#!/usr/bin/env python
# -*-coding:utf-8 -*
import os
import sys
import time
import stat
import pysftp as sftp
import subprocess
import paramiko
import datetime
from datetime import datetime, timedelta
from time import mktime, strftime, localtime, sleep
u_name = 'robi'
pswd = 'xxxx'
port = 22
r_ip = 'xxx.xxx.x.xxx'
sec_key = '/home/rob/key_detail'
myconn = paramiko.SSHClient()
myconn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
my_rsa_key = paramiko.RSAKey.from_private_key_file(sec_key)
session = myconn.connect(r_ip, username=u_name, password=pswd, port=port,
pkey=my_rsa_key)
# print myconn.get_transport().is_active()
# path1 = "/home/rob_remote/sensors/12/tem_data/temp.dat"
fmt = '%Y-%m-%d %H:%M:%S'
path1 = "/home/rob_remote/sensors/12/tem_data/temp.dat"
path2 = '/home/new/loc/13/press/pressure.dat'
start_time = datetime.strptime("2015-06-25 14:50:00", fmt)
latest_time = datetime.now()
step_size = 10
diff = latest_time - start_time
minutes_values = diff.total_seconds()/60
expected = int(minutes_values/step_size)
sftp = myconn.open_sftp()
with sftp.open(path1) as f:
read = f.readlines()[4:]
get_values = []
for line in read:
line = line.strip().split(',')
start_date = line[0]
start_date = datetime.strptime(start_date, fmt)
current_time = datetime.now()
step_size = 5
differ_time = current_time - start_date
minutes_values = differ_time.total_seconds()/60
get_values.append(int(minutes_values/step_size))
# print 'get_values:::::::::::::::::::', max(get_values)
get_val = max(get_values)
.
.
.
.
有人可以帮助我或指导我解决这个问题。我会很感激。
2017-08-16
robbin
+2
你周围有时间字符串双引号,所以你需要剥去这些出或将它们添加到格式字符串''‘%Y-%间%d%H:%M:%S’ '' –
+0
@EdChum你可以举一个小例子如何将“”添加到格式字符串。我尝试了2个解决方案,但他们不工作。 –
+0
@EdChum我试过这个解决方案data_tmp = [v.replace(“\”“,”“)for v in start_date],但导致TypeError:必须是字符串,而不是列表 –