Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Execute python script in load script

Hi,

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 12 'ble';

and I get no error in qlik sense, bu 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?

17 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Can you specify a full path to the python interpreter?

Anonymous
Not applicable
Author

Hi,

My path is

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

why? Is there a "right" and "wrong" path for qlik sense?

Peter_Cammaert
Partner - Champion III
Partner - Champion III

You misunderstood me. I meant "can you add a full path to the command you are trying to execute using the EXECUTE script statement".

Most of these EXECUTE problems have to do with the fact that the Windows shell can't find the program to execute. Even cmd.exe may require a full path sepcification before it can be found.

Anonymous
Not applicable
Author

hmmm I can see your point...

Now I try with :

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);

But it still doesn't work...

any idea?

Anonymous
Not applicable
Author

Is there a way that python would writ in console... so that I would see if it is executing.... I see that if I mistype the path Qlik Sense give me an error

The handle is invalid:,.....

Is this mean that if no error presents, that script is executed? But why then it would not save a file,...

Peter_Cammaert
Partner - Champion III
Partner - Champion III

No idea. Permssions? Can you check whether you python script - when launched via the EXECUTE statement - is able to write to a global directory like C:\Temp?

Anonymous
Not applicable
Author

I am not sure what do you mean by that,... I am sure that Qlik Sense could save file (I exported csv file), but I can't check if python has permissions because the it doesn't display any error. Terminal could save to file,..

Anonymous
Not applicable
Author

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

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Indeed, your attempt to write a file seems straightforward enough. What I meant by my request was to try to write to a global directory that is accessible to everyone (like C:\Temp)

If you start ProcessExplorer or Task Manager, do you see the python interpreter being launched when you run the load script? For a better chance of python.exe being visualized, add some code to your script that takes a while to complete, like a loop.