NoneType“对象没有属性”

2024-05-20 18:45:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在openstack设置中尝试nova list cli命令时,出现以下错误。 NoneType“对象没有属性”getitem'

 DEBUG (shell:777) 'NoneType' object has no attribute '__getitem__'
    Traceback (most recent call last):
      File "/opt/stack/python-novaclient/novaclient/shell.py", line 774, in main
        OpenStackComputeShell().main(map(strutils.safe_decode, sys.argv[1:]))
      File "/opt/stack/python-novaclient/novaclient/shell.py", line 685, in main
        self.cs.authenticate()
      File "/opt/stack/python-novaclient/novaclient/v1_1/client.py", line 169, in authenticate
        self.client.authenticate()
      File "/opt/stack/python-novaclient/novaclient/client.py", line 382, in authenticate
        auth_url = self._v2_auth(auth_url)
      File "/opt/stack/python-novaclient/novaclient/client.py", line 469, in _v2_auth
        return self._authenticate(url, body)
      File "/opt/stack/python-novaclient/novaclient/client.py", line 484, in _authenticate
        return self._extract_service_catalog(url, resp, respbody)
      File "/opt/stack/python-novaclient/novaclient/client.py", line 307, in _extract_service_catalog
        self.auth_token = self.service_catalog.get_token()
      File "/opt/stack/python-novaclient/novaclient/service_catalog.py", line 29, in get_token
        return self.catalog['access']['token']['id']
    TypeError: 'NoneType' object has no attribute '__getitem__'
    ERROR: 'NoneType' object has no attribute '__getitem_

那是什么意思?我的openstack设置有什么问题吗?还是与python相关的错误?


Tags: inpyselfclientauthurlstackline
3条回答

错误消息

TypeError: 'NoneType' object has no attribute '__getitem__'

原因

在另一个函数调用的参数列表中调用void方法,导致了“NoneType”错误。

解决方案

为了解决这个问题,我刚刚让void方法返回了我在另一个函数的参数列表中需要的值。

字面上说,'NoneType' object has no attribute...意味着您试图访问属性或调用具有值None的对象的方法。

实际上,这意味着您可能在某个地方有一个bug,该bug在为变量赋值之前使用变量,或者使用返回None的函数中的值。调试这个问题的第一步是问自己“为什么这个变量被设置为None?”。

在这种特定情况下,self.catalogself.catalog['access']self.catalog['access']['token']都是None

相关问题 更多 >