将客户端凭据流用于Python请求
对于一个项目,我尝试使用请求模块在Python中获取访问令牌 它与GET方法一起工作:将客户端凭据流用于Python请求,python,Python,对于一个项目,我尝试使用请求模块在Python中获取访问令牌 它与GET方法一起工作: import requests, json # Oauth API - GET call - Winnie project access_token = requests.get("https://api.ebanking.com/oauth/access_token?grant_type=client_credentials&client_id=27c5b286-62a6-45c7-be
import requests, json
# Oauth API - GET call - Winnie project
access_token = requests.get("https://api.ebanking.com/oauth/access_token?grant_type=client_credentials&client_id=27c5b286-62a6-45c7-beda-abbaea6eecf2&client_secret=6731de76-14a6-49ae-97bc-6eba6914391e").json()["access_token"]
但是,不是使用POST方法:
import requests, json
data = {'grant_type':'client_credentials',
'client_id':'27c5b286-62a6-45c7-beda-abbaea6eecf2',
'client_secret':'6731de76-14a6-49ae-97bc-6eba6914391e'}
# Oauth API - POST call - Winnie project
access_token = requests.post(url = "https://api.ebanking.dev/oauth", data = data).json()["access_token"]
有什么想法吗?我也有同样的问题,但当您使用客户端凭据进行身份验证时,您必须对身份验证进行编码,并将标题和正文按顺序排列
import base64, requests, sys
client_id = "client_id"
client_secret = "client_secret"
# Encode the client ID and client secret
authorization = base64.b64encode(bytes(client_id + ":" + client_secret, "ISO-8859-1")).decode("ascii")
headers = {
"Authorization": f"Basic {authorization}",
"Content-Type": "application/x-www-form-urlencoded"
}
body = {
"grant_type": "client_credentials"
}
response = requests.post("https://url.com", data=body, headers=headers)
print(response.text)
欢迎来到堆栈溢出!请拿下,阅读主题,和,并提供一个。