Ask Your Question
0

problem in get openstack token by cURL

asked 2016-05-16 09:05:02 -0500

daryana gravatar image

I write the scrip for connect to openstack to list images:

import requests
import json

def token():
username="admin"
password="admin123"

headers = {
    'Content-Type': 'application/json',
 }

data = '{"auth": {"tenantName": "", "passwordCredentials": {"username": "'""+username+""'", "password": "'""+password+""'"}}}'

url= 'http://x.x.x.x:5000/v2.0/tokens'

tokenObjectFormat = requests.post(url, headers=headers, data=data)
tokenJsonFormat = tokenObjectFormat.json()
tokenId = tokenjsonformat[u'access'][u'token'][u'id']
return tokenId

def image(id4):  
headers = {
    'X-Auth-Token': id4 ,
}   
url = 'http://x.x.x.x:8774/v2/admin/images'
fimage = requests.get(url, headers=headers)
print(fimage.json())

tokenId = token()
image(tokenId)

I get the token, but I get the authentication error for image list definition. what is the problem? And can I use curl without token or just by admin username and password?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-16 11:37:44 -0500

Matt G gravatar image

You need to specify a value for tenantName (I'd guess "admin" in this case) in the 'data' dictionary in token(). Also, change 'url' in image() to http://x.x.x.x:8774/v2/images

edit flag offensive delete link more

Comments

I did your solution, but when I try to print 'fimage' to test, it return 'Response [404]', it means NOT FOUND, but I know I have Image in my openstack. do I need to do something in openstack configuration (forexample in keystone.conf)?

daryana gravatar imagedaryana ( 2016-05-16 22:34:27 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2016-05-16 09:05:02 -0500

Seen: 78 times

Last updated: May 16 '16