AttributeError:"str"对象没有属性"isoformat" [英] AttributeError: 'str' object has no attribute 'isoformat'

查看:55
本文介绍了AttributeError:"str"对象没有属性"isoformat"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码,而且我不知道如何解决问题.代码:

I have code, and I don't know how to solve problem. Code:

import dateutil.parser
import datetime
from novaclient.v2 import client as nova_client
from keystoneclient.auth.identity import v2
from keystoneclient import session 

auth=v2.Password(auth_url="http://openstack2-prakt.in.linux.edu.lv:5000/v2.0",
             username="***",
             password="****",
             tenant_name="********")
sess=session.Session(auth=auth)
nova=nova_client.Client(version="2", session=sess)

usage_list=nova.usage.get(tenant_id="**************",start='%Y-%m-%d', end='%Y-%m-%d')
for us in usage_list:
    print us.total_vcpus_usage

执行代码后,出现下一个问题:

After I execute code, there is next problem:

No handlers could be found for logger "keystoneclient.auth.identity.base"

Traceback (most recent call last):
  File "/home/eleonora/PycharmProjects/untitled/nova test.py", line 32, in <module>
    usage_list=nova.usage.get(tenant_id="c56f75091edc4480a204e5549ef11664",start='%Y-%m-%d', end='%Y-%m-%d')
  File "/usr/local/lib/python2.7/dist-packages/novaclient/v2/usage.py", line 60, in get
   (tenant_id, start.isoformat(), end.isoformat()),
AttributeError: 'str' object has no attribute 'isoformat'

推荐答案

'%Y-%m-%d'不是日期时间对象,而是字符串,但是您(或其他代码)正在尝试用作日期时间对象.

'%Y-%m-%d' is not datetime object but string but you (or some other code) are trying to use it as datetime object.

这篇关于AttributeError:"str"对象没有属性"isoformat"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆