← Back to team overview

openstack team mailing list archive

Programming OpenStack Compute API - 1.1 Mistake

 

Hello Anne

I am playing with the OpenStack API on my StackOps environment to get an
idea of how to use it for scripts to programm some little scripts.
I read the documentation "Programming OpenStack Compute API - 1.1" and
tried the code examples but at one specific script the machine threw me an
error. The mentioned script is found in Chapter "2. The Basics" in the
section "Using Python to Obtain the Authentication Token". If you
copy-paste the script in a file, adjust the variables like username,
password, etc. and then execute the file, you will receive a parse error
from python:

"root@nova-controller:~# ./gettoken.py
{"badRequest": {"message": "Cannot parse auth", "code": "400", "details":
"Expecting object: line 1 column 43 (char 43)"}}
Traceback (most recent call last):
  File "./gettoken.py", line 41, in <module>
    apitoken = dd['auth']['token']['id']
KeyError: 'auth'"

This is due to the fact that line 39 tries to extract the api token from
the response ['auth']['token']['id'], which rather ought to be
['access']['token']['id']

old: apitoken = dd['auth']['token']['id']
new: apitoken = dd['access']['token']['id']

As you might have noticed you receive an answer, which states "badRequest".
>From former experience with the API, I remembered that this means that
there is something wrong with the credentials provided to keystone. I
checked the params variable and realized that there was no information
about the tenantid. Therefore I edited the line like this:

old:params = '{"passwordCredentials":{"username":osuser,
"password":ospassword}}'
new: params = '{"auth":{"passwordCredentials":{"username": osuser,
"password":"ospassword"}, "tenantId":ostenant}}'

After that the script worked like a charm. Could it be that this error only
occurs on StackOps environments or is it a spelling error?

PS: I learned a lot from the "Programming OpenStack Compute API"
documentation. Thank you very much for this superb how to!

Best regards,
Nicolas

-- 
Freundliche Grüsse,
Nicolas Odermatt

Follow ups