我试图使用Python发布一个不和谐的web钩子URL,但是只要出现embeds
字段,它就会返回{'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)
我尝试过各种版本的不和谐API,但结果总是一样的。
发布于 2022-01-05 11:36:37
我把它换了
requests.post(url, headers=headers, data=data)
使用
requests.post(url, json=data)
发布于 2022-06-25 08:38:20
尝尝这个。我认为请求库可能添加了一个名为content-type
的标题,它与标题Content-Type
冲突,从而使不和谐的Content-Type
返回一个错误:
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, json=data)
https://stackoverflow.com/questions/70585716
复制相似问题