-
-
Save netmanchris/e0c574b1d5ba37cc3a66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def imc_creds(): | |
''' This function prompts user for IMC server information and credentials and stores | |
values in url and auth global variables''' | |
global url, auth, r | |
imc_protocol = input( | |
"What protocol would you like to use to connect to the IMC server: \n Press 1 for HTTP: \n Press 2 for HTTPS:") | |
if imc_protocol == "1": | |
h_url = 'http://' | |
else: | |
h_url = 'https://' | |
imc_server = input("What is the ip address of the IMC server?") | |
imc_port = input("What is the port number of the IMC server?") | |
imc_user = input("What is the username of the IMC eAPI user?") | |
imc_pw = input('''What is the password of the IMC eAPI user?''') | |
url = h_url + imc_server + ":" + imc_port | |
auth = requests.auth.HTTPDigestAuth(imc_user, imc_pw) | |
test_url = '/imcrs' | |
f_url = url + test_url | |
try: | |
r = requests.get(f_url, auth=auth, headers=headers) | |
# checks for requests exceptions | |
except requests.exceptions.RequestException as e: | |
print("Error:\n" + str(e)) | |
print("\n\nThe IMC server address is invalid. Please try again\n\n") | |
imc_creds() | |
if r.status_code != 200: # checks for valid IMC credentials | |
print("Error: \n You're credentials are invalid. Please try again\n\n") | |
imc_creds() | |
else: | |
print("You've successfully access the IMC eAPI") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment