4

I am trying to generate a oauth access token for experian's sandbox API (they give information on credit information). Their tutorial Says to run this (fake data) to get an access token:

curl -X POST
-d '{ "username":"[email protected]", "password":"YOURPASSWORD"}'
-H "Client_id: 3QC11Sm45ti8wEG0d9A5hma5XIlGG7U9"
-H "Client_secret: ipu3WQDqTEjqZDXW"
-H "Content-Type: application/json"
"https://sandbox-us-api.experian.com/oauth2/v1/token"

How would I run this in python? I tried this among a lot of other things:

data = { "username" : "[email protected]", "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)

Any help would be greatly appreciated

0

1 Answer 1

7

Almost there, just need to parse the response:

import json

data = { "username" : "[email protected]", "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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.