首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用stackexchange时出错

使用stackexchange时出错
EN

Stack Overflow用户
提问于 2022-10-14 21:21:08
回答 2查看 44关注 0票数 -1

当我使用编辑问题API时,我会得到这个错误:

代码语言:javascript
复制
{"error_id":400,"error_message":"site is required","error_name":"bad_parameter"}

这是我的密码:

代码语言:javascript
复制
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})
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-15 04:33:08

从官方的docs页面中,我得到了javascript请求结构如下

代码语言: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中,您可以像这样使用

代码语言:javascript
复制
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})
票数 0
EN

Stack Overflow用户

发布于 2022-10-14 21:55:55

您使用的requests.post函数不正确。如果希望在请求中发送参数,请使用params参数并将参数作为字典传递。

代码语言:javascript
复制
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}) 
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74074986

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档