python - 想要使用 python swiftclient 将 sqlite.db 文件上传到 swift 容器并且总是得到 utf-8 错误

标签 python swift python-3.x openstack openstack-swift

我正在尝试在我的 python 代码中使用 swiftclient 将 sqlite.db(二进制文件)上传到 swift 容器。

导入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

我使用的代码是:

导入swiftclient bmdatabase = "./logs/test.db' 打开(bmdatabase,'r')作为 bmdatabase_file: #偏僻的 correctbmdatabasename = bmdatabase.replace("./logs/", "") swift_conn.put_object(container_name,correctbmdatabasename, contents=bmdatabase_file.read())

最佳答案

我终于自己找到了,如果我想读取一个二进制文件我必须用'rb'读取它

喜欢

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())

关于python - 想要使用 python swiftclient 将 sqlite.db 文件上传到 swift 容器并且总是得到 utf-8 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58394265/

相关文章:

python - 有没有办法检查列表项是否是列表中的唯一项目?

javascript - 类 Python 的 JavaScript 继承

ios - Swift iOS 14 Firebase 警告——这个旧式函数定义之前没有原型(prototype)

ios - 试图从 Objective-C 转向 Swift VC

python - 无法在python3中导入tensorflow并出现ImportError : This package should not be accessible on Python 3

Python有效地提取字典值并创建html页面

python - 在 Python 列表理解中是否可以访问项目索引?

python - 在 Python 中没有回溯的断言

ios - 将 Facebook SDK 与 Xcode Swift 项目集成 - AppDelegate 错误?

python-3.x - MXNet (python3) 将残差卷积结构定义为来自 Gluon 模块的 Block