libcloud-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torf <m...@torf.cc>
Subject Binary data in Python 3 using LocalStorageDriver
Date Mon, 20 Jul 2015 21:43:18 GMT
Hi,

I'm trying to store binary data in Python 3 to a ``LocalStorageDriver``
instance. If I upload data via ``upload_object`` from a file on disk and
then use ``download_object_as_stream`` I get a stream of bytes, as
expected. However, uploading a stream of bytes manually using
``upload_object_via_stream`` fails:


>>> container.upload_object_via_stream(io.BytesIO(b'foobar'), 'key')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/home/torf/projects/coba/venv/lib/python3.4/site-packages/libcloud/storage/base.py",
line 157, in upload_object_via_stream
    iterator, self, object_name, extra=extra, **kwargs)
  File
"/home/torf/projects/coba/venv/lib/python3.4/site-packages/libcloud/storage/drivers/local.py",
line 497, in upload_object_via_stream
    obj_file.close()
  File
"/home/torf/projects/coba/venv/lib/python3.4/site-packages/libcloud/storage/drivers/local.py",
line 69, in __exit__
    raise value
  File
"/home/torf/projects/coba/venv/lib/python3.4/site-packages/libcloud/storage/drivers/local.py",
line 495, in upload_object_via_stream
    obj_file.write(data)
TypeError: must be str, not bytes


The problem seems to be that ``LocalStorageDriver`` opens the target
file for writing in text mode ('w') instead of binary mode ('wb').

I couldn't find any information on whether keys and values are supposed
to be (Unicode) strings or bytes (or both), so I am not sure whether
this is a bug in ``LocalStorageDriver`` or a misunderstanding on my side.

This is on Python 3.4 and LibCloud 0.17.0.


Regards,
Torf

Mime
View raw message