Ask Your Question

Ian_Stuart's profile - activity

2019-04-02 08:35:14 -0500 received badge  Popular Question (source)
2019-04-02 08:35:14 -0500 received badge  Famous Question (source)
2019-04-02 08:35:14 -0500 received badge  Notable Question (source)
2017-05-30 06:11:03 -0500 asked a question Getting the swiftClient copy command to work


Can't set the destination for a copy


  • Python 3, python-swiftclient, python-keystoneclient, and keystoneauth1
  • Connection is good, and I can create objects in the store


def cp(self, old_path, new_path):
    with SwiftService() as swift:
        _obj = SwiftCopyObject(old_path, 
                               options={"Destination": '/my_container/' + new_path})
        response = swift.copy( self.container, [_obj],
            { "Destination": 'my_container' + new_path })
        for r in response:
      except SwiftError as e:

If I call self.cp('untitled.ipynb', 'renamed.ipynb'), I get a dump something like:

{'action': 'copy_object',
 'container': 'my_container',
 'destination': None,
 'fresh_metadata': False,
 'headers': {},
 'object': 'Untitled.ipynb',
 'response_dict': {'headers': {'content-length': '0',
                           'content-type': 'binary/octet-stream',
                           'date': 'Tue, 30 May 2017 10:44:49 GMT',
                           'etag': 'd588d3885f633322f6733b2e0f33df71',
                           'last-modified': 'Tue, 30 May 2017 10:44:49 GMT',
                           'x-copied-from': 'kiz/Untitled.ipynb',
                           'x-copied-from-account': '0edbdcab2cda436a90ab73a26b77c83e',
                           'x-copied-from-last-modified': 'Tue, 30 May '
                                                          '2017 10:44:44 '
                           'x-object-meta-mtime': '1496141084.000000',
                           'x-trans-id': 'tx0000000000000002af6e0-00592d4d20-3d698d-default'},
               'reason': 'Created',
               'response_dicts': [{'headers': {'content-length': '0',
                                               'content-type': 'binary/octet-stream',
                                               'date': 'Tue, 30 May 2017 '
                                                       '10:44:49 GMT',
                                               'etag': 'd588d3885f633322f6733b2e0f33df71',
                                               'last-modified': 'Tue, 30 '
                                                                'May 2017 '
                                                                '10:44:49 '
                                               'x-copied-from': 'kiz/Untitled.ipynb',
                                               'x-copied-from-account': '0edbdcab2cda436a90ab73a26b77c83e',
                                               'x-copied-from-last-modified': 'Tue, '
                                                                              '30 '
                                                                              'May '
                                                                              '2017 '
                                                                              '10:44:44 '
                                               'x-object-meta-mtime': '1496141084.000000',
                                               'x-trans-id': 'tx0000000000000002af6e0-00592d4d20-3d698d-default'},
                                   'reason': 'Created',
                                   'status': 201}],
               'status': 201},
 'success': True}

Why is "Destination" None?

How do I actually set it?

2017-05-23 10:38:48 -0500 received badge  Editor (source)
2017-05-23 10:13:27 -0500 asked a question Python SwiftService download and getting the content of the file

I am writing a Contentsmanager for a Jupyter project, where we will be storing data in a SwiftStore.

I'm mostly getting there, and can upload data to the store:

# horribly paraphrased
def write(self, path, content):
    _opts = {'object_uu_threads' : 20}
    with SwiftService( options = _opts ) as swift, OutputManager() as out_manager:
        output = io.StringIO(content)
        response = swift.upload(self.container, [output])

(you will notice the contents are in a variable)

What I need to do is go the other way: download into a variable

I suspect it's something to do with the options passed into the download function.... perhaps the out_file parameter.... but

  1. Is that actually what that parameter is for, and
  2. How to I (pythonically) set that up to be a variable in my code?

post-acceptance edit:

This is my current read

## This works by downloading the file to disk then reading the contents of
## that file into memory, before deleting the file
## NOTE this is reading text files!
## NOTE this really only works with files in the local direcotry, but given local filestore will disappear when the docker ends, I'm not too bothered.
def read(self, path):
    content = ''
    with SwiftService() as swift:
      response =, objects=[path])
      for r in response:
        if r['success']:
          filename = open( r['path'] )
          content =
          os.remove( r['path'] )
    return content

It is not elegant.