我正在尝试通过Yelp API进行身份验证,这是我得到的:
{“error”:{“description”:“找不到客户端id或客户端密钥参数。确保在主体中使用application/x-www-form-urlencoded内容类型“,”code“:“VALIDATION_ERROR”}}在主体中提供client_id和client_secret
这是我在Python中定义的方法,我已经安装了Python Flask。在此之前,我从未使用过API:
@app.route("/run_post")
def run_post():
url = "https://api.yelp.com/oauth2/token"
data = {'grant_type': 'client_credentials',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'Content-type': 'application/x-www-form-urlencoded'}
body = requests.post(url, data=json.dumps(data))
return json.dumps(body.json(), indent=4)
我遵循@destiner的方法,并将内容类型添加到头文件中,它起作用了。以下是生成的代码:
数据应作为
application/x-www-form-urlencoded
传递,因此不应序列化请求参数。您也不应该将Content-Type
指定为参数,它属于requestheaders最终代码:
相关问题 更多 >
编程相关推荐