keystone REST API and python [closed]

asked 2014-06-09 17:41:04 -0600

conrosebraugh gravatar image

updated 2014-06-09 17:52:07 -0600

I am running Havana, and I have verified the install of install of the identity service by using running the following:

keystone --os-username=uname --os-password=pword --os-auth-url=http://localhost:35357/v2.0 token-get

which returns the token just fine. When I run the following python script on another machine on my network I get an HTTP 401 when using port 9696 and HTTP 400 when using port 35357.

import requests

username = 'uname'

password = 'pword'

payload = {'auth': {'tenantName': 'tenant1', 'passwordCredentials': {'username': uname, 'password': pword}}}

print'', data=payload)

What am I missing? The guide I am using is (here).

EDIT: I have also tried using curl and the following command: url -d '{"auth":{“tenantName": “tenant1", "passwordCredentials": {"username": “uanme", "password": “pword"}}}' -H "Content-type: application/json"

but that returns the following: {"error": {"message": "Expecting to find valid JSON in request body. The server could not comply with the request since it is either malformed or otherwise incorrect. The client is assumed to be in error.", "code": 400, "title": "Bad Request"}}

I got that curl command from ( .

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by conrosebraugh
close date 2014-06-10 13:25:18.748469

1 answer

Sort by » oldest newest most voted

answered 2014-06-09 19:57:47 -0600

larsks gravatar image

updated 2014-06-09 19:59:40 -0600

Your first problem is that Keystone doesn't listen on port 9696 (that's Neutron). However, it does listen on port 35357 (as well as port 5000), and your problem stems from the fact you are not sending Keystone the data in the format it expects.

If you read the requests documentation, you will find that when you pass a dictionary to the data parameter of that it form-encodes the data. Keystone wants a JSON-encoded payload. So you need this:

res ='http://localhost:5000/v2.0/tokens', 
                headers={'content-type': 'application/json'},

Another way of resolving this sort of problem is enabling debugging in the requests library (see this question on StackOverflow), and checking how the request that you're making compares to what you see when running the keystone client with --debug.

edit flag offensive delete link more


Thank you! I thought I read in the docs that the default content-type that the service expects is json, but that must have been the default return type.

conrosebraugh gravatar imageconrosebraugh ( 2014-06-10 10:24:21 -0600 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-06-09 17:41:04 -0600

Seen: 3,136 times

Last updated: Jun 09 '14