<div><div>Hello Anne</div><div><br></div><div>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.</div><div>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:</div>
<div><br></div><div>"root@nova-controller:~# ./gettoken.py</div><div>{"badRequest": {"message": "Cannot parse auth", "code": "400", "details": "Expecting object: line 1 column 43 (char 43)"}}</div>
<div>Traceback (most recent call last):</div><div>  File "./gettoken.py", line 41, in <module></div><div>    apitoken = dd['auth']['token']['id']</div><div>KeyError: 'auth'"</div>
<div><br></div><div>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']</div>
<div><br></div><div>old: apitoken = dd['auth']['token']['id']</div><div>new: apitoken = dd['access']['token']['id']</div><div><br></div><div>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:</div>
<div><br></div><div>old:params = '{"passwordCredentials":{"username":osuser, "password":ospassword}}'</div><div>new: params = '{"auth":{"passwordCredentials":{"username": osuser, "password":"ospassword"}, "tenantId":ostenant}}'</div>
<div><br></div><div>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?</div><div><br></div><div>PS: I learned a lot from the "Programming OpenStack Compute API" documentation. Thank you very much for this superb how to!</div>
<div><br></div><div>Best regards,</div><div>Nicolas</div><div><br></div><div>-- </div><div>Freundliche Grüsse,</div><div>Nicolas Odermatt</div><div><br></div>
</div>