Search code examples
python-2.7openstackkeystone

How to establish authorized request with keystone using python-openstack client API v3


I have problems with python-openstackclient library.When i run this code to authorize with keystone:

from keystoneclient import session
from keystoneclient.v3 import client
from keystoneclient.auth.identity import v3
password = v3.PasswordMethod(username='idm',password='idm',user_domain_name='idm')
auth = v3.Auth(auth_url='http://127.0.0.1:5000/v3',auth_methods=[password],project_id='idm')
sess = session.Session(auth=auth)
keystone = client.Client(session=sess)
keystone.users.list()

Im getting this error: keystoneclient.openstack.common.apiclient.exceptions.Unauthorized: The request you have made requires authentication. (HTTP 401)

But when i try openstack client program:

openstack user list

It gives me good output. I have next global variables in my .bashrc:

export OS_SERVICE_ENDPOINT=http://127.0.0.1:35357/v3
export OS_AUTH_URL=http://127.0.0.1:5000/v3
export OS_TENANT_NAME=idm
export OS_USERNAME=idm
export OS_PASSWORD=idm
export OS_IDENTITY_API_VERSION=3
export OS_URL=http://127.0.0.1:35357/v3

What could be the problem with that python code? Thanks!


Solution

  • I managed to do it like this:

    from keystoneclient import session
    from keystoneclient.v3 import client
    from keystoneclient.auth.identity import v3
    auth = v3.Password(auth_url='http://127.0.0.1:5000/v3',user_id='idm',password='idm',project_id='2545070293684905b9623095768b019d')
    sess = session.Session(auth=auth)
    keystone = client.Client(session=sess)
    keystone.users.list()