当AWS Cognito授权端点返回错误请求(400),通常是因为请求中的参数有误或缺失。以下是一个解决方法的示例代码:
import requests
# 设置Cognito授权端点URL
url = 'https://your-cognito-endpoint-url'
# 准备请求参数
client_id = 'your-client-id'
username = 'your-username'
password = 'your-password'
# 发送请求
response = requests.post(url, data={
'grant_type': 'password',
'client_id': client_id,
'username': username,
'password': password
})
# 检查响应状态码
if response.status_code == 400:
print('请求错误:', response.text)
else:
print('授权成功')
请确保将your-cognito-endpoint-url
替换为实际的Cognito授权端点URL,your-client-id
替换为您的客户端ID,your-username
替换为您的用户名,your-password
替换为您的密码。
如果请求中的参数正确无误,但仍然收到400错误,可能是其他原因导致的。您可以检查AWS Cognito控制台中的错误日志,以获取更详细的错误信息。