为什么这个请求返回400?(Python3请求)

p8ekf7hl  于 2023-02-18  发布在  Python
关注(0)|答案(1)|浏览(169)

我有麻烦发送后请求,因为它返回一个错误400,而不是预期的204,尽管事实上,发送一个类似的请求在相同的风格似乎工作正常的其他部分相同的网站。
下面是一个接受google chrome请求的例子:

Request URL: https://discordapp.com/api/v6/users/@me/relationships
Request Method: POST
Status Code: 204 
Remote Address: IP
Referrer Policy: no-referrer-when-downgrade
access-control-allow-credentials: true
access-control-allow-headers: Content-Type, Authorization, X-Track, X-Super-Properties, X-Context-Properties, X-Failed-Requests, X-Fingerprint, X-RPC-Proxy, X-Debug-Options, If-None-Match
access-control-allow-methods: POST, GET, PUT, PATCH, DELETE
access-control-allow-origin: https://discordapp.com
alt-svc: clear
cf-ray: 4ae0db43cf473464-LHR
date: Sun, 24 Feb 2019 09:20:28 GMT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
status: 204
strict-transport-security: max-age=31536000; includeSubDomains
via: 1.1 google
:authority: discordapp.com
:method: POST
:path: /api/v6/users/@me/relationships
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-GB
authorization: USER TOKEN
content-length: 46
content-type: application/json
cookie: __cfduid=dda2a2e2ad66d52129871a4410708b3941545858349; _ga=GA1.2.393621366.1545937419; locale=en-US; _gid=GA1.2.803863711.1550442266; _gat_UA-53577205-2=1
dnt: 1
origin: https://discordapp.com
referer: https://discordapp.com/channels/@me
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
x-context-properties: eyJsb2NhdGlvbiI6IkFkZCBGcmllbmQifQ==
x-fingerprint: 547382949931384833.wx3cZudz6zpRaSSwwn2N0xyAmAo
{username: "USERNAME", discriminator: 999}
discriminator: 9999
username: "USERNAME"

下面是我尝试发送请求的代码:

headers={"authorization": "TOKEN HERE"}
params={"username": "USERNAME", "discriminator": 9999}

r = requests.post("https://canary.discordapp.com/api/v6/users/@me/relationships",headers=headers,params=params)
print(r.status_code)

我以前收到过一个结构类似的删除聊天消息的请求,该请求工作正常:

requests.delete("http://canary.discordapp.com/api/v6/channels/" + CHANNEL ID + "/messages/" + MESSAGE ID, headers={"authorization": "TOKEN"})
tp5buhyn

tp5buhyn1#

参数必须以json格式传入:

r = requests.post("https://discordapp.com/api/v9/users/@me/relationships",headers=headers,json=params)

相关问题