当我使用编辑问题API时,我会得到这个错误:
{"error_id":400,"error_message":"site is required","error_name":"bad_parameter"}这是我的密码:
r = requests.post(f"https://api.stackexchange.com/2.3/questions/{qid}/suggested-edit/add", json={"access_token": at, "site": "stackoverflow", "title":t,"body":str(b),"key":key})发布于 2022-10-15 04:33:08
从官方的docs页面中,我得到了javascript请求结构如下
await fetch("https://api.stackexchange.com/2.3/questions/11/suggested-edit/add", {
"credentials": "include",
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Content-Type": "application/x-www-form-urlencoded",
"X-Requested-With": "XMLHttpRequest",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin"
},
"referrer": "https://api.stackexchange.com/docs/create-question-suggested-edit",
"body": "id=11&body=111&key=111&access_token=111&preview=true&filter=default&site=stackoverflow",
"method": "POST",
"mode": "cors"
});在Python中,您可以像这样使用
r = requests.post(f"https://api.stackexchange.com/2.3/questions/{qid}/suggested-edit/add",headers={"Content-Type": "application/x-www-form-urlencoded"}, data={"access_token": at, "site": "stackoverflow", "title":t,"body":str(b),"key":key,"id":qid})发布于 2022-10-14 21:55:55
您使用的requests.post函数不正确。如果希望在请求中发送参数,请使用params参数并将参数作为字典传递。
r = requests.post(f"https://api.stackexchange.com/2.3/questions/{qid}/suggested-edit/add",params={"access_token": at, "site":"stackoverflow","title":t,"body":str(b),"key":key}) https://stackoverflow.com/questions/74074986
复制相似问题