Python Swift无法建立连接并放置对象

时间:2019-01-11 07:38:07

标签: python openstack openstack-swift

我正在尝试使用python swift client来替换现有的curl命令,该命令的格式为:

curl -u "user:password" <url>/<container_name>/<file>

上面的curl命令有效,不需要任何其他身份验证,它连接到url并放置一个对象。我尝试遵循提到的示例here并编写以下代码

>>> import swiftclient
>>> user = '<user_name>:<password>'
>>> url = '<url>'
>>> conn = swiftclient.Connection(user=user,authurl=url)
>>> container_name='<some_name>'
>>> conn.put_container(container_name)

但是失败,并显示以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 1808, in put_container
    query_string=query_string)
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 1710, in _retry
    self.url, self.token = self.get_auth()
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 1662, in get_auth
    timeout=self.timeout)
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 682, in get_auth
    timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 514, in get_auth_1_0
    conn.request(method, parsed.path, '', headers)
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 444, in request
    files=files, **self.requests_args)
  File "/usr/local/lib/python2.7/dist-packages/swiftclient/client.py", line 427, in _request
    return self.request_session.request(*arg, **kwarg)
  File "/home/adupa/.local/lib/python2.7/site-packages/requests/sessions.py", line 498, in request
    prep = self.prepare_request(req)
  File "/home/adupa/.local/lib/python2.7/site-packages/requests/sessions.py", line 441, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/home/adupa/.local/lib/python2.7/site-packages/requests/models.py", line 310, in prepare
    self.prepare_headers(headers)
  File "/home/adupa/.local/lib/python2.7/site-packages/requests/models.py", line 444, in prepare_headers
    check_header_validity(header)
  File "/home/adupa/.local/lib/python2.7/site-packages/requests/utils.py", line 944, in check_header_validity
    "bytes, not %s" % (name, value, type(value)))
requests.exceptions.InvalidHeader: Value for header {x-auth-key: None} must be of type str or bytes, not <type 'NoneType'>

有什么方法可以使用python swift仅通过用户名和密码建立连接,而没有任何标头或Auth令牌

0 个答案:

没有答案