相关疑难解决方法(0)

TypeError:b'1'不是JSON可序列化的

我试图以JSON发送POST请求.

*电子邮件变量的类型为"字节"

def request_to_SEND(email, index):
    url = "....."
    data = {
        "body": email.decode('utf-8'),
        "query_id": index,
        "debug": 1,
        "client_id": "1",
        "campaign_id": 1,
        "meta": {"content_type": "mime"}
    }
    headers = {'Content-type': 'application/json'}

    try:
        response = requests.post(url, data=json.dumps(data), headers=headers)
    except requests.ConnectionError:
        sys.exit()

    return response
Run Code Online (Sandbox Code Playgroud)

我收到错误:

 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
Run Code Online (Sandbox Code Playgroud)

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

python json http-post python-3.x

30
推荐指数
1
解决办法
4万
查看次数

标签 统计

http-post ×1

json ×1

python ×1

python-3.x ×1