-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode_credentials.py
30 lines (23 loc) · 977 Bytes
/
encode_credentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import base64
def get_encoded_credentials():
while True:
try:
# Prompt the user to enter their client ID and secret
client_id = input("Enter your client ID: ").strip()
if not client_id:
raise ValueError("Client ID cannot be empty.")
client_secret = input("Enter your client secret: ").strip()
if not client_secret:
raise ValueError("Client secret cannot be empty.")
# Concatenate the client ID and secret with a colon separator
credentials = f"{client_id}:{client_secret}"
# Encode as ASCII and then Base64
encoded_credentials = base64.b64encode(credentials.encode("ascii")).decode("ascii")
return encoded_credentials
except ValueError as ve:
print(f"Invalid input: {ve}\nPlease try again.\n")
except Exception as e:
print(f"Error: {e}\nPlease try again.\n")
# Call the function to get the encoded credentials
encoded_credentials = get_encoded_credentials()
print(f"The encoded credentials are: {encoded_credentials}")