cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
188 stars 107 forks source link

TM1py script does not work with Integrated Security mode 5 #1117

Closed TM1pylearner closed 4 months ago

TM1pylearner commented 4 months ago

We are trying to run one of the sample code to check the system name and the we are getting the error as unauthorized. Below is the code that we are trying and the error that we are getting. We have installed python in one of our server. We tried replacing the company address with local host but didnot work. We donot have SSo configured but a different namespace in our cognos configuration. The test user has admin access in the application. Can someone help us with this connection errors. Thank you

import getpass
from distutils.util import strtobool

from TM1py.Services import TM1Service

# Parameters for connection
user = "SA-M210-TESTUSER1-V"
password = "5v:YT~7ugGa2:Vc/WmT2"
namespace = "adEUns"
gateway = None
address = "company address"
port = "8061"
ssl = True

try:
 with TM1Service(
    address=address,
    port=port,
    user=user,
    password=password,
    namespace=namespace,
    gateway=gateway,
    ssl=ssl,
) as tm1:
    server_name = tm1.server.get_server_name()
    print("Connection to TM1 established!! your Servername is: {}".format(server_name))
except Exception as e:
    print("\nERROR:")
))

ERROR Text: '' - Status Code: 401 - Reason: 'Unauthorized' - Headers: {'Content-Type': 'text/plain', 'Content-Length': '0', 'Connection': 'keep-alive', 'Set-Cookie': 'TM1SessionId=e0dMOe1jHlXLJMkXVjRUfZ4OXjg; Path=/api/; HttpOnly; Secure', 'WWW-Authenticate': 'CAMPassport https://Company.address:9300/bi/v1/disp, CAMNamespace'}

cubewise-nswan commented 4 months ago

Hi TM1pylearner, could you try a couple of things.

Make sure the namespace is in the correct case ( it is case sensitive) Remove the gateway option in the call (as per below)

with TM1Service( address=address, port=port, user=user, password=password, namespace=namespace, ssl=ssl ) as tm1:

Good reference is here. https://code.cubewise.com/blog/how-to-authenticate-to-tm1-with-tm1py/

Hope this gets you going