Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

keystone Client returns 401

I am running a sample code which just list down the networks available.

please find below code 

#!/usr/bin/python
from os import environ as env
import keystoneclient.v2_0.client as ksclient
from neutronclient.v2_0 import client as neutronclient
keystone = ksclient.Client(auth_url=env['OS_AUTH_URL'],
    username=env['OS_USERNAME'],
    password=env['OS_PASSWORD'],
    tenant_name=env['OS_TENANT_NAME'])
endpoint_url = keystone.service_catalog.url_for(service_type='network')
print endpoint_url
token = keystone.auth_token
neutron = neutronclient.Client(endpoint_url=endpoint_url, token=token)
neutron.list_networks()

But i am facing following error

Traceback (most recent call last):
  File "./list_network.py", line 8, in <module>
    tenant_name=env['OS_TENANT_NAME'])
  File "/usr/lib/python2.6/site-packages/keystoneclient/v2_0/client.py", line 147, in __init__
    self.authenticate()
  File "/usr/lib/python2.6/site-packages/keystoneclient/utils.py", line 318, in inner
    return func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/keystoneclient/httpclient.py", line 425, in authenticate
    resp = self.get_raw_token_from_identity_service(**kwargs)
  File "/usr/lib/python2.6/site-packages/keystoneclient/v2_0/client.py", line 181, in get_raw_token_from_identity_service
    return plugin.get_auth_ref(self.session)
  File "/usr/lib/python2.6/site-packages/keystoneclient/auth/identity/v2.py", line 79, in get_auth_ref
    authenticated=False, log=False)
  File "/usr/lib/python2.6/site-packages/keystoneclient/session.py", line 430, in post
    return self.request(url, 'POST', **kwargs)
  File "/usr/lib/python2.6/site-packages/keystoneclient/utils.py", line 318, in inner
    return func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/keystoneclient/session.py", line 346, in request
    raise exceptions.from_response(resp, method, url)
keystoneclient.openstack.common.apiclient..exceptions.Unauthorized: Could not find project, ESS. (HTTP 401)

When i rune "neutron net-list" from the command line it works absolutely fine.

Has anything needs to be changed on the keystone to accept API calls ? am i missing anything. I checked the environment variables. They are set corrctly in both the cases .