我是openstack环境的新手,我正在尝试使用Openstack API。 我在执行基本脚本以使用neutron API列出网络时遇到以下错误。
脚本
#!/usr/bin/env python
from neutronclient.v2_0 import client as neutronClient
import os
neutronConnection = neutronClient.Client(
username=os.environ['OS_USERNAME'],
password=os.environ['OS_PASSWORD'],
tenant_name=os.environ['OS_TENANT_NAME'],
auth_url=os.environ['OS_AUTH_URL']
)
print neutronConnection
neutronConnection.format = 'json'
neutronConnection.list_networks()
错误
neutronConnection.list_networks()
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 98, in with_params
ret = self.function(instance, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 339, in list_networks
**_params)
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 1334, in list
for r in self._pagination(collection, path, **params):
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 1347, in _pagination
res = self.get(path, params=params)
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 1320, in get
headers=headers, params=params)
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 1297, in retry_request
headers=headers, params=params)
File "/usr/lib/python2.6/site-packages/neutronclient/v2_0/client.py", line 1232, in do_request
self.httpclient.authenticate_and_fetch_endpoint_url()
File "/usr/lib/python2.6/site-packages/neutronclient/client.py", line 152, in authenticate_and_fetch_endpoint_url
self.authenticate()
File "/usr/lib/python2.6/site-packages/neutronclient/client.py", line 249, in authenticate
self._authenticate_keystone()
File "/usr/lib/python2.6/site-packages/neutronclient/client.py", line 228, in _authenticate_keystone
allow_redirects=True)
File "/usr/lib/python2.6/site-packages/neutronclient/client.py", line 138, in _cs_request
raise exceptions.Unauthorized(message=body)
neutronclient.common.exceptions.Unauthorized: {"error": {"message": "Could not find project, ESS.", "code": 401, "title": "Unauthorized"}}
答案 0 :(得分:1)
该错误表示您在OS_TENANT_NAME环境变量中传递的租户名称存在问题。它的价值是“ESS”,并且没有具有该名称的租户,或者用户无权访问它。
如果您能够运行neutron CLI,请打印出您在那里使用的环境变量并将其复制到您的代码中。