value计算机格式,ValueError:时间数据与远程计算机文件上的格式“%Y-%m-%d%H:%M:%S”不匹配...

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:必须是字符串,而不是列表 –

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值