NoneType'对象没有属性'__getitem__'

use*_*122 2 python openstack openstack-nova

我在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_
Run Code Online (Sandbox Code Playgroud)

_"

这是什么意思?我的openstack设置有什么问题,或者是一些python相关的错误?

Bry*_*ley 7

从字面上看,'NoneType' object has no attribute...意味着您正在尝试访问属性或在具有该值的内容上调用方法None.

实际上,这意味着在分配值之前使用变量或使用返回的函数中的值时,您可能会遇到某个错误None.调试此问题的第一步是问自己"为什么将此变量设置为None?".

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