Hi All,
i was trying to generate OTCS token so that i can authenticate and write a script for business workspace creation. Through postman i tested the API and works fine. Referring to that, i wrote a python script. I can see that authentication or token generation is not happening. am posting my code below.As i am pretty new to Python and incase Anyone came across similar issues, please guide me. Right now its just executing the catch block.
import requests
import http
def get_ticket(): auth_url = "http://CS URL/OTCS/cs.exe/api/v1/auth"
OTCSToken = { 'Username = username & Password = pass' }
headers = { 'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.request("POST",auth_url,headers=headers, data=OTCSToken)
response_data = response.json()
if 'access_token' in response_data:
return response_data['access_token']
else: raise ValueError("Failed to obtain access token")
def main(): try:
OTCSToken = get_ticket()
print('Tokren Generated {OTCSToken}')
except Exception as e:
print('An error occurred {e}')
if __name__=='__main__': main()