首页 > 解决方案 > 将具有不可序列化元素的字典转换为字节并返回

问题描述

我必须根据我的项目的需要实施以下方案。

  1. 我正在从函数中检索字典(其元素不可序列化)
  2. 我想将上面提到的 dict 转换为字节(所以我可以将它作为对客户端的响应发送回)
  3. 接下来,我希望客户端(在步骤 2 中)接收到的这些字节通过我的 Web 服务再次发送,并再次转换为其初始格式(dict)。

我尝试使用以下示例从这里开始json.dumps

cipher_text = hyb_abe.encrypt(master_public_key, fileInBase64Format, policy) #this function comes from the charm-crypto framework and returns a dictionary
encrypted_bytes = json.dumps(cipher_text) # produces error TypeError: Object of type 'Element' is not JSON serializable

hyb_abe.encrypt函数代码在这里

但我得到

TypeError: Object of type 'Element' is not JSON serializable

我的情况有什么解决方法?

编辑

调试模式下字典值的照片

在此处输入图像描述

标签: pythondictionaryserializationflaskcharm

解决方案


推荐阅读