import requests import json def main(): print("I am main function") cdp = input("Enter p for Production account or i for Internal account\n") if cdp == "i": base_url = "https://internal-apigw.central.arubanetworks.com" print("The URL used is {}".format(base_url)) elif cdp == "p": base_url = "https://app1-apigw.central.arubanetworks.com" print("The URL used is {}".format(base_url)) else: print("Wrong Input. p or i are valid inputs") cid = input("Enter the Client ID for the App\n") csecret = input("Enter the Client secret for the App\n") rtoken = input("Enter the latest valid refresh token for the App\n") url1 = "/oauth2/token" url3 = base_url + url1 params = {"client_id": cid, "grant_type": "refresh_token", "refresh_token": rtoken, "client_secret": csecret} print("Contacting URL:", url3) resp = requests.post(url3, params=params) if resp.status_code != 200: print("Failure! The code is: {}".format(resp.status_code)) else: print("Awesome!\nThe access token is: {} \nThe refresh token is: {}\nThese are valid for 2 hours only!".format(resp.json()['access_token'], resp.json()['refresh_token'])) return if __name__ == '__main__': main()