【发布时间】:2019-05-15 05:34:16
【问题描述】:
我是 Python 3 和 Flask 的新手,我目前正在构建一个简单的 Web 应用程序来使用来自 Spotify API 的数据。
OAuth 2.0 身份验证流程几乎可以正常工作,因为我可以调用https://accounts.spotify.com/authorize:
在对 API 的 POST 请求期间,我收到 HTTP 400:
authentication_token = request.args['code']
code_payload = {
"grant_type": "authorization_code",
"code": str(authentication_token),
"redirect_uri": REDIRECT_URI
}
encoded_oauth2_tokens = base64.b64encode('{}:{}'.format(CLIENT_ID, CLIENT_SECRET).encode())
headers = {"Authorization": "Basic {}".format(encoded_oauth2_tokens)}
post_request = requests.post(SPOTIFY_TOKEN_URL, data=code_payload, headers=headers)
post_request.raise_for_status()
编辑:响应正文:
"GET / HTTP/1.1" 302 - b'{"error":"invalid_client"}'
不确定请求中有什么问题。
【问题讨论】:
-
响应的正文是什么?
-
@Kaszaq 使用 print(str(post_request.content), file=sys.stderr) 打印响应正文。我没有得到太多。
标签: python python-3.x rest oauth-2.0 spotify