我正在编写一个代码来使用 python swift 客户端库访问对象存储。该程序的目的是使用 swift 客户端 API 读取、写入和删除对象存储中的 CSV 文件。我可以知道出了什么问题。我从一个网站得到这个代码。有没有其他方法可以从 python 访问对象存储?
import swiftclient.client
from keystoneclient import client
print 'i am fine'
conn = swiftclient.Connection(key="password",
authurl='https://identity.open.softlayer.com',
#auth_version='3',
os_options={"project_id": 'project-id',
"user_id": 'user_id',
"region_name": "dallas"})
container_name = 'test'
# File name for testing
file_name = 'result.csv'
# Create a new container
conn.put_container(container_name)
print "nContainer %s created successfully." % container_name
ERROR:swiftclient:Auth GET failed: https://identity.open.softlayer.com 300 Multiple Choices
Traceback (most recent call last):
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1553, in _retry
self.url, self.token = self.get_auth()
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1507, in get_auth
timeout=self.timeout)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 593, in get_auth
timeout=timeout)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 468, in get_auth_1_0
http_status=resp.status, http_reason=resp.reason)
ClientException: Auth GET failed: https://identity.open.softlayer.com 300 Multiple Choices
ClientException Traceback (most recent call last)
<ipython-input-5-3708d247f0cc> in <module>()
15
16 # Create a new container
---> 17 conn.put_container(container_name)
18 print "nContainer %s created successfully." % container_name
19
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in put_container(self, container, headers, response_dict)
1641 """Wrapper for :func:`put_container`"""
1642 return self._retry(None, put_container, container, headers=headers,
-> 1643 response_dict=response_dict)
1644
1645 def post_container(self, container, headers, response_dict=None):
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in _retry(self, reset_func, func, *args, **kwargs)
1551 try:
1552 if not self.url or not self.token:
-> 1553 self.url, self.token = self.get_auth()
1554 self.http_conn = None
1555 if self.service_auth and not self.service_token:
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(self)
1505 cacert=self.cacert,
1506 insecure=self.insecure,
-> 1507 timeout=self.timeout)
1508 return self.url, self.token
1509
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(auth_url, user, key, **kwargs)
591 cacert=cacert,
592 insecure=insecure,
--> 593 timeout=timeout)
594 elif auth_version in AUTH_VERSIONS_V2 + AUTH_VERSIONS_V3:
595 # We are handling a special use case here where the user argument
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth_1_0(url, user, key, snet, **kwargs)
466 raise ClientException('Auth GET failed', http_scheme=parsed.scheme,
467 http_host=conn.host, http_path=parsed.path,
--> 468 http_status=resp.status, http_reason=resp.reason)
469 if snet:
470 parsed = list(urlparse(url))
***ClientException: Auth GET failed: https://identity.open.softlayer.com 300 Multiple Choices***
*****With auth_version enabled:*****
ERROR:swiftclient:Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)
Traceback (most recent call last):
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1553, in _retry
self.url, self.token = self.get_auth()
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 1507, in get_auth
timeout=self.timeout)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 617, in get_auth
auth_version=auth_version)
File "/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.py", line 543, in get_auth_keystone
raise ClientException('Authorization Failure. %s' % err)
ClientException: Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)
i am fine
---------------------------------------------------------------------------
ClientException Traceback (most recent call last)
<ipython-input-21-d0874a2c5851> in <module>()
15
16 # Create a new container
---> 17 conn.put_container(container_name)
18 print "nContainer %s created successfully." % container_name
19
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in put_container(self, container, headers, response_dict)
1641 """Wrapper for :func:`put_container`"""
1642 return self._retry(None, put_container, container, headers=headers,
-> 1643 response_dict=response_dict)
1644
1645 def post_container(self, container, headers, response_dict=None):
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in _retry(self, reset_func, func, *args, **kwargs)
1551 try:
1552 if not self.url or not self.token:
-> 1553 self.url, self.token = self.get_auth()
1554 self.http_conn = None
1555 if self.service_auth and not self.service_token:
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(self)
1505 cacert=self.cacert,
1506 insecure=self.insecure,
-> 1507 timeout=self.timeout)
1508 return self.url, self.token
1509
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth(auth_url, user, key, **kwargs)
615 insecure=insecure,
616 timeout=timeout,
--> 617 auth_version=auth_version)
618 else:
619 raise ClientException('Unknown auth_version %s specified.'
/gpfs/fs01/user/s1ab-0eb9620648b3ce-07c8d52a704f/.local/lib/python2.7/site-packages/swiftclient/client.pyc in get_auth_keystone(auth_url, user, key, os_options, **kwargs)
541 raise ClientException(msg)
542 except exceptions.AuthorizationFailure as err:
--> 543 raise ClientException('Authorization Failure. %s' % err)
544 service_type = os_options.get('service_type') or 'object-store'
545 endpoint_type = os_options.get('endpoint_type') or 'publicURL'
ClientException: Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)