我正在尝试为 experian 的沙箱 API 生成一个 oauth 访问 token (它们提供有关信用信息的信息)。 他们的tutorial说要运行这个(假数据)来获取访问 token :
curl -X POST
-d '{ "username":"youremail@email.com", "password":"YOURPASSWORD"}'
-H "Client_id: 3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9"
-H "Client_secret: ipu3WQDqTEjqZDXW"
-H "Content-Type: application/json"
"https://sandbox-us-api.experian.com/oauth2/v1/token"
我如何在 python 中运行它?我在很多其他事情中尝试过这个:
data = { "username" : "youremail@email.com", "password":"YOURPASSWORD"}
headers = {"Client_id": "3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9", "Client_secret": "ipu3WQDqTEjqZDXW", "Content-Type": "application/json"}
response = requests.post("https://sandbox-us-
api.experian.com/oauth2/v1/token", data=data, headers=headers)
任何帮助将不胜感激
请您参考如下方法:
差不多了,只需要解析响应:
import json
data = { "username" : "youremail@email.com", "password":"YOURPASSWORD"}
headers = {"Client_id": "3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9", "Client_secret": "ipu3WQDqTEjqZDXW", "Content-Type": "application/json"}
response = requests.post("https://sandbox-us-api.experian.com/oauth2/v1/token", data=data, headers=headers)
if response.status_code in [200]:
tok_dict = json.loads(response.text)
print(tok_dict)
issued_at = tok_dict["issued_at"]
expires_in = tok_dict["expires_in"]
token_type = tok_dict["token_type"]
access_token = tok_dict["access_token"]
else:
print(response.text)
