Python 类型错误:b';1';JSON不可序列化

Python 类型错误:b';1';JSON不可序列化,python,json,python-3.x,http-post,Python,Json,Python 3.x,Http Post,我正在尝试以JSON的形式发送POST请求 *电子邮件变量的类型为“bytes” 我得到一个错误: File "C:\Python34\lib\json\encoder.py", line 173, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: b'1' is not JSON serializable 你能告诉我我做错了什么吗?发生这种情况是因为你在数据dict(b'1')中

我正在尝试以JSON的形式发送POST请求

*电子邮件变量的类型为“bytes”

我得到一个错误:

 File "C:\Python34\lib\json\encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'1' is not JSON serializable

你能告诉我我做错了什么吗?

发生这种情况是因为你在
数据
dict(
b'1'
)中传递了
字节
对象,可能是
索引的值。在
json之前,您需要将其解码为
str
对象。dumps
可以使用它:

data = {
    "body": email.decode('utf-8'),
    "query_id": index.decode('utf-8'),  # decode it here
    "debug": 1,
    "client_id": "1",
    "campaign_id": 1,
    "meta": {"content_type": "mime"}
}

你能给我们一些我们可以复制的东西吗?我把
“Hello”
放在
电子邮件中
index
0
,然后复制粘贴
数据的定义和
json。转储(数据)
工作得很好。UnicodeDecodeError:“utf-8”编解码器无法解码字节0xdamy数据是位类型的,当我将其存储在会话和打印会话中时,我得到了这个@dano.为避免
AttributeError:'NoneType'对象没有属性“decode”
错误
email.decode('utf-8'),如果email!=没有其他电子邮件
@dano:当我在从odoodb检索图像时出错时,它对我也很有效。我使用rec.image.decode('utf-8')。解决了我的类型错误:bytes类型的对象不可JSON序列化---。非常感谢。
data = {
    "body": email.decode('utf-8'),
    "query_id": index.decode('utf-8'),  # decode it here
    "debug": 1,
    "client_id": "1",
    "campaign_id": 1,
    "meta": {"content_type": "mime"}
}