Execute python script in Qlik Sense load script

2019-06-12 06:56发布

I am trying to run python script inside my load script in Qlik Sense app.

I know that I need to put OverrideScriptSecurity=1 in Settings.ini

I put

Execute py lib://python/getSolution.py 100 'bla'; // 100 and 'bla' are parameters

and I get no error in qlik sense, but script is not executed (I think) because inside the script I have

f = open("file.xml", "wb")
f.write(xml)
f.close

and file is not saved.

If I run script from terminal, then script is properly executed.

What could go wrong?

By the way, my full path to python interpreter is

C:\Users\Marko Z\AppData\Local\Programs\Python\Python37-32\python.exe

EDIT :

Even if I add this

Set vPythonPath = "C:\Users\Marko Z\AppData\Local\Programs\Python\Python37-32\python.exe";
Set vPythonFile = "C:\Users\Marko Z\Documents\Qlik\Sense\....\getSolution.py";

Execute $(vPythonPath) $(vPythonFile);

I get the same behaviour. No error, but not working,... I even see that if I change path (incorrect path) it give me an error, but incorrect file it doesn't give me an error.... (but I am sure it is the right file path...)

My python code is

xml = "Marko"
xml = xml.encode('utf-8')
f = open("C:\\Users\\Marko Z\\Test.xml", "wb")
f.write(xml)
f.close

2条回答
ゆ 、 Hurt°
2楼-- · 2019-06-12 07:14

I figure out what was wrong. For all others that would have similar problems:

Problem is in space in path. If I move my script in c:\Windows\getSolution.py it work. I also need to change the python path to c:\Windows\py.exe

so end script looks like:

Execute c:\Windows\py.exe c:\Windows\getSolution.py 100 'bla';

But I still need to figure how to work with space in path...

查看更多
男人必须洒脱
3楼-- · 2019-06-12 07:31

Strange. With exactly the same python file and QS script the result file is generated correctly.

The content of my settings.ini.

[Settings 7]
StandardReload=0
OverrideScriptSecurity=1    

According to Qlik's documentation there should be an empty line at the end (point 4 from the lists)

查看更多
登录 后发表回答