How to execute a python script on a remote desktop [TM1py]

Post Reply
Emixam
Regular Participant
Posts: 156
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

How to execute a python script on a remote desktop [TM1py]

Post by Emixam »

Hello,

I have developed a python script on my personal laptop using PyCharm and it works perfectly.

Code: Select all

from TM1py.Services import TM1Service
with TM1Service(
        address="tm1-dev@domain.com",
        port="12345",
        user="admin",
        password="apple",
        namespace="cognos",
        gateway="http://abc.domain.com:80/ibmcognos/cgi-bin/cognosisapi.dll",
        ssl=False) as tm1:
    # Some code
I want this script to be executed through a chore (TI) and I wonder what's the best way to do it ? Since we are using PA on premise, I was thinking about creating a .bat file on the server with the following syntax but it doesn't seems to work:

Code: Select all

"C:\Users\myUserName\AppData\Local\Programs\Python\Python38-32.exe" "D:\TM1\TM1py_script.py"
Even when I execute my batch file manually it doesn't work. What's bother me the most is it's working using pycharm on my machine but not through a simple batch file.

We are using PA 2.0.7 on premise.

Thanks in advance.

EDIT:

More information here : https://code.cubewise.com/tm1py-help-co ... m1-process
Last edited by Emixam on Thu Sep 03, 2020 8:54 pm, edited 1 time in total.
ascheevel
Community Contributor
Posts: 312
Joined: Fri Feb 15, 2013 5:49 pm
OLAP Product: TM1
Version: PA 2.0.9.1
Excel Version: 365
Location: Minneapolis, USA

Re: How to execute a python script on a remote desktop [TM1py]

Post by ascheevel »

Calling a python script from a batch file should be no problem provided you have Python and the required TM1Py library installed on the same server that TM1 is running on. Careful using mapped drives in a script as it may not be mapped the same on the TM1 server, best to use UNC path instead.
Emixam
Regular Participant
Posts: 156
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: How to execute a python script on a remote desktop [TM1py]

Post by Emixam »

Thanks Ascheevel.

Looks like there is something weird with TM1py..

First I have TM1py installed on the server:

Image

And when I try to execute my script directly from the command prompt ( I added python to PATH ), I have the following error...

Image

EDIT:

Seems like i'm not the only one with this issue...

https://github.com/cubewise-code/tm1py/issues/129
ascheevel
Community Contributor
Posts: 312
Joined: Fri Feb 15, 2013 5:49 pm
OLAP Product: TM1
Version: PA 2.0.9.1
Excel Version: 365
Location: Minneapolis, USA

Re: How to execute a python script on a remote desktop [TM1py]

Post by ascheevel »

If you're supplying a username and password, skip the gateway parameter.
Emixam
Regular Participant
Posts: 156
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: How to execute a python script on a remote desktop [TM1py]

Post by Emixam »

I comment the gateway parameter and now I have this error:

Code: Select all

  File "D:\TM1\abc\zOther\DisconnectAllUser.py", line 2, in <module>
    with TM1Service(
  File "C:\Users\UserName\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TM1py\Services\TM1Service.py", line 13, in __init__
    self._tm1_rest = RestService(**kwargs)
  File "C:\Users\UserName\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TM1py\Services\RestService.py", line 165, in __init__
    self._start_session(
  File "C:\Users\UserName\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TM1py\Services\RestService.py", line 302, in _start_session
    response = self.GET(url=url)
  File "C:\Users\UserName\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TM1py\Services\RestService.py", line 76, in wrapper
    self.verify_response(response=response)
  File "C:\Users\UserName\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TM1py\Services\RestService.py", line 372, in verify_response
    raise TM1pyRestException(response.text,
TM1py.Exceptions.Exceptions.TM1pyRestException: Text:  Status Code: 401 Reason: Unauthorized Headers: {'Content-Type': 'text/plain', 'Content-Length': '0', 'Connection': 'keep-alive', 'Set-Cookie': 'TM1SessionId=aEs1x5jFYl-xlGCxoh19mA; Path=/api/; HttpOnly', 'WWW-Authenticate': 'CAMPassport http://tm1-dev.domain.com:80/ibmcognos/cgi-bin/cognosisapi.dll, CAMNamespace'}
ascheevel
Community Contributor
Posts: 312
Joined: Fri Feb 15, 2013 5:49 pm
OLAP Product: TM1
Version: PA 2.0.9.1
Excel Version: 365
Location: Minneapolis, USA

Re: How to execute a python script on a remote desktop [TM1py]

Post by ascheevel »

Are you sure you're using the proper username/password/namespace for your setup?
Emixam
Regular Participant
Posts: 156
Joined: Tue May 21, 2019 3:33 pm
OLAP Product: TM1
Version: PA 2.0.x
Excel Version: 2016
Location: The Internet

Re: How to execute a python script on a remote desktop [TM1py]

Post by Emixam »

ascheevel wrote: Thu Sep 03, 2020 7:39 pm Are you sure you're using the proper username/password/namespace for your setup?
With all the trial and errors I deleted the namespace parameter. All is good now ! Thanks a lot ascheevel !!
Post Reply