我正在尝试调用Product Hunt V2 GraphQL API, 当我使用Python“请求”库执行POST请求时,出现以下错误
{'error': 'Bad Request','status': 400}
我在邮递员中使用GraphQL正文类型尝试了相同的请求,并且成功获得了200状态代码,因此我认为问题出在我在请求正文中传递GraphQL代码的方式上。这是我使用的代码:
import requests,json
url = "https://api.producthunt.com/v2/api/graphql"
payload = {
"query": "query { posts(first: 1) { edges { node { id,name } } } }"
}
header = {
"accept": "application/json","Content-Type": "application/json","Authorization": "Bearer MYTOKEN","Host": "https://api.producthunt.com/v2/api/graphql"
}
response_decoded_json = requests.post(url,headers=header,data=payload)
response_json
在查看引用时,我尝试使用“ json.dumps”在Json中对有效负载进行编码,但是我总是得到相同的400状态代码。
我在做什么错了?