Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要使用 python 将存储在 ubunutu 服务器上的数据库中的图像作为二进制文件发送。
我已经成功地将文件从二进制转换为 Base64 编码的字符串。但是,我不确定如何将此编码字符串附加到 Python 中的默认字符串。例如
"Text" + ": " + base64.b64encode("text")
有什么建议或建议吗?
更新:
它会产生此错误:
TypeError:无法连接 'str' 和 'builtin_function_or_method' 对象”
如果你只想要 JSON 输出,你可以这样做:
return '{"image": "' +base64.b64encode("text") + '"}'
import json json.dumps({'image_base64': base64.b64encode(file(image_filename).read())})
有库时不要手动构建 json。