我在尝试通过 python 将文件保存到 IBM 对象存储时遇到一些问题。我从 bluemix 帐户复制了以下凭据(下面省略了详细信息)。
credentials = {
"auth_url": "https://identity.open.softlayer.com",
"project": <my project>,
"projectId": <my project id>,
"region": "dallas",
"userId": <user id>,
"username": <user name>,
"password": <password>,
"domainId": <domain Id>,
"domainName": <domain Name>,
"role": <role>
}
下面是我用来尝试将文件从 io import StringIO import requests import json 保存到容器中的 python 脚本
url1 = ''.join(['https://identity.open.softlayer.com', '/v3/auth/tokens'])
data = {'auth': {'identity': {'methods': ['password'],
'password': {'user': {'name': credentials['username'],'domain': {'id': credentials['domainId']},
'password': credentials['password']}}}}}
headers1 = {'Content-Type': 'application/json'}
resp1 = requests.post(url=url1, data=json.dumps(data), headers=headers1)
resp1_body = resp1.json()
for e1 in resp1_body['token']['catalog']:
if(e1['type']=='object-store'):
for e2 in e1['endpoints']:
if(e2['interface']=='public'and e2['region']=='dallas'):
url2 = ''.join([e2['url'],'/', container, '/', filename])
s_subject_token = resp1.headers['x-subject-token']
headers2 = {'X-Auth-Token': s_subject_token, 'accept': 'application/json'}
print(url2)
resp2 = requests.post(url=url2, data=filename, headers=headers2)
print(resp2.text)
return StringIO(resp2.text)
filename = "sample.png"<br>
post_object_storage_file("democontainer", filename)
我似乎通过 resp1 获得了一个令牌并获得了 url2。但是,当我打印 resp2.text 时,我得到一个“禁止”响应。我是该存储容器的管理员,所以我不明白为什么我无法访问它。
我是 IBM 对象存储的新手,因此任何建议都会有所帮助。
谢谢。