Openstack令牌,我可以使用curl获取令牌,但不能使用urllib

时间:2015-06-08 09:08:18

标签: curl urllib openstack

sandy @ Swift_PC:〜$ curl -D- -H'X-Storage-User:Lucy'

sandy@Swift_PC:~$ curl -D- -H 'X-Storage-User:Lucy' http://192.168.119.89:8080/auth/v1.0

HTTP/1.1 200 OK
X-Storage-Url: http://192.168.119.89:8080/v1/AUTH_Lucy
X-Auth-Token: AUTH_tk713d067336d24348bcea1ab220965785
Content-Type: text/html; charset=UTF-8
X-Storage-Token: AUTH_tk713d067336d24348bcea1ab220965785
X-Trans-Id: tx8a03bc278f6d4ab899a25-00557554df
Content-Length: 0
Date: Mon, 08 Jun 2015 08:39:59 GMT

我可以使用curl获取X-Storage-token。

import urllib,httplib,json
from urlparse import urlparse

user = "Lucy"
url = "192.168.119.89:8080"
ports = "/auth/v1.0"
params = urllib.urlencode({})
headers = {"X-Storage-User":user,"Content-type":"application/json"}
conn = httplib.HTTPConnection(url)
conn.request("GET","%s" %ports,params,headers)

response = conn.getresponse()
data = response.read()
print response

我想获得curl表示的令牌。 它什么都不返回。 如果我不想以其他方式获得带卷曲的令牌,我该怎么办?

谢谢

1 个答案:

答案 0 :(得分:0)

X-Storage-Token位于标题中,而不在正文中。

尝试token = response.getheader('X-Storage-Token')