Page 1 of 1
How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 5:54 pm
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
Re: How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 6:30 pm
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.
Re: How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 6:45 pm
by Emixam
Thanks Ascheevel.
Looks like there is something weird with TM1py..
First I have TM1py installed on the server:
And when I try to execute my script directly from the command prompt ( I added python to PATH ), I have the following error...
EDIT:
Seems like i'm not the only one with this issue...
https://github.com/cubewise-code/tm1py/issues/129
Re: How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 6:53 pm
by ascheevel
If you're supplying a username and password, skip the gateway parameter.
Re: How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 7:11 pm
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'}
Re: How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 7:39 pm
by ascheevel
Are you sure you're using the proper username/password/namespace for your setup?
Re: How to execute a python script on a remote desktop [TM1py]
Posted: Thu Sep 03, 2020 8:16 pm
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 !!