请求正文包含无效 JSON

The request body contains invalid JSON

我正在尝试使用 Python 请求 POST 到一个不和谐的网络钩子 URL,但是只要 embeds 字段存在,它 returns {'code': 50109, 'message': 'The request body contains invalid JSON.'}。如果我删除 embeds 并只留下 content,它将毫无错误地发送。

我的代码是:

url = "https://discord.com/api/webhooks/[redacted]/[redacted]"

headers = {
    "Content-Type": "application/json"
}

data = {
  "username": "Webhook",
  "content": "Hello, World!",
  "embeds": [{
    "title": "Hello, Embed!",
    "description": "This is an embedded message."
  }]
}

res = requests.post(url, headers=headers, data=data)

我试过各种版本的 Discord API,但结果总是一样。

我通过替换

让它工作
requests.post(url, headers=headers, data=data)

requests.post(url, json=data)