Unable to generate OTCS token through Rest API Python Script
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()
Comments
-
my postman suggested this I see in yours your payload is a JSON, in mine it is a string . Sorry, I am not a python programmer.
import requests
url = "https://myserver:8443/otcs/cs.exe"
payload = 'username=Admin&password=*******!'headers = { 'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)in most of my actual work, I stay away from getting a OTCSTicket and get it from OTDS as it is better when it encounters multiple servers.Also I put my servers in https so that is the only change
0 -
Hi @appuq ,
Thanks for the reply. i was able to get the token with slight modifications in my code.
0
Categories
- All Categories
- 117 Developer Announcements
- 52 Articles
- 147 General Questions
- 133 Services
- 56 OpenText Hackathon
- 35 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 8.9K Extended ECM
- 912 Cloud Fax and Notifications
- 81 Digital Asset Management
- 9.3K Documentum
- 29 eDOCS
- 166 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 4 XM Fax