0

i am trying to upload a sqlite.db(binary file) to a swift container using swiftclient in my python code.

import swiftclient swift_conn.put_object

File "/usr/lib/python3.7/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbc in position 43: invalid start byte

the code i am using is:

import swiftclient bmdatabase = "./logs/test.db' with open(bmdatabase, 'r') as bmdatabase_file: #remote correctbmdatabasename = bmdatabase.replace("./logs/", "") swift_conn.put_object(container_name,correctbmdatabasename, contents=bmdatabase_file.read())

1
  • code seems incomplete, where does swift_conn comes from? Commented Nov 10, 2022 at 9:43

1 Answer 1

1

I finally found it by myself, if I want to read a binary file I have to read it with 'rb'

like

import swiftclient
bmdatabase = "./logs/test.db'
    with open(bmdatabase, 'rb') as bmdatabase_file:
                #remote
                correctbmdatabasename = bmdatabase.replace("./logs/", "")
                swift_conn.put_object(container_name,correctbmdatabasename,
                                      contents=bmdatabase_file.read())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.