Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
On Demand Webinar: See Why Thousands of QlikView Users Have Switched to Qlik Sense. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
zadravecm
Contributor III
Contributor III

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

Can you specify a full path to the python interpreter?

zadravecm
Contributor III
Contributor III

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

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.

zadravecm
Contributor III
Contributor III

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?

zadravecm
Contributor III
Contributor III

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

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?

zadravecm
Contributor III
Contributor III

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,..

zadravecm
Contributor III
Contributor III

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

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.