Error when using "Load python script activity"

I am trying to load a simple python script, which should work (I got it from uipath forum concerning python), but when I run the workflow, I get an error which states:

Message: Error loading Python script

Exception Type: System.InvalidOperationException

What do I do?

Can you attach sample workflow file.

There are two activities w.r.t python - load python script and run python script.

Regards,
Karthik Byggari

2 Likes

Hi,

I have installed python 3.6 at C:\Python36 and tried to execute the example program. getting an error for pythn script load activity may be because of the file paths. Could you please help me on this. attached the zip file.Python36.zip (59.4 KB)

1 Like

Hi,

There was a minor syntax error in your python script.
Previous syntax : print data
Corrected Syntax: print(data)
I have made the changes and tested with UiPath.
It’s working good now.

Thanks and Regards,
Rahul

1 Like

Hello Rahul,

Even I have a similar issue - Error loading python script, I’m not attaching .py file in load python script instead hard coded the code in the activity. Could you pleas help me resolve this.

Using Python 3.6 - 32 Bit

import hmac
import hashlib, sys
import base64
import time
import math

key=“AKI1339272018102317140956787461”
data = str(math.trunc(time.time()))
print (data)
a = base64.b64encode(hmac.new(b’key’, b’msg=data’, digestmod=hashlib.sha256).digest())
print (a)

This code calculates Epoch time and Digest using Epoch Time and AKI.

I have attached my workflow, thanks for your time.
TEST.xaml (9.6 KB)

Hello Prasanth,

I have attached the .py file and loaded the python script. It worked fine. But whenever you want to return the output make sure you write a python program using a function and use Invoke python method activity to pass the inputs. I’m attaching the Python file along with the workflow. Please go through it and reply back if there’s any concern.

In the python scope, make sure u give the target as x86 as you are using python 32 bit.

I’m not able to attach the python file. So typing it here:

def Apachfn(keyinput):
import hmac
import hashlib, sys
import base64
import time
import math
key=keyinput
data = str(math.trunc(time.time()))
print (data)
a = base64.b64encode(hmac.new(b’key’, b’msg=data’, digestmod=hashlib.sha256).digest())
print (a)
return("Data: “+data+” "+"A: "+str(a))

Thanks and Regards,
Rahul, PTEST.xaml (10.4 KB)

1 Like

Hello Rahul,

Thanks for your response.

Not sure where it went wrong, but when I ran the code started getting error such as return outside the function and unexpected indentation.

Attaching the script the in .txt file. I tried fixing the indentation issue and return outside the function. But repeatedly getting the same error.

Could you please help me solve this issue.

It will be huge help for me to complete this piece of code.

Thanks,
Prasanth

Hi Prasanth,

It was indentation issue. In python, when you’re defining a function everything should be inside the function.


As you can see above, everything is written inside the function. But in your code, after import math the next line is not in the same indentation.

Thanks and Regards,
Rahul, P

Thanks a lot Rahul.

Hi Prasanth,

Can you mark it as solved?

Hi Rahul,

I am getting the same error in load python script activity.
Here is my python code. There are no errors in the python editor that I have used and when i run it directly the script is executing. But while loading the script in uipath its giving an error as mentioned above by Sirtosych. Please find the code below:

from bs4 import BeautifulSoup
import os

def download():
canID = “123456”
filepath = r"C:\Users\abhilashasinha3\Desktop"
f = open(os.path.join(filepath, canID, “cv_webpage.html”), “r”)
soup = BeautifulSoup(f.read(),‘html5lib’)
table_body = soup.find(“table”, {“class”:“docs_upload_table”})
lst = list()
title = ‘’
for tr in table_body.find_all(‘tr’):
if tr:
typ = tr.find_all(‘td’)
if typ:
if not typ[0].find(‘a’):
title = typ[0].get_text()
if tr.find(‘a’):
lst.append({‘type’ : title, ‘document’ : tr.find(‘a’).get_text(), ‘onclick’:tr.find(‘a’).get(‘onclick’)})

with open(os.path.join(filepath, canID, "output.csv"), 'w') as fr:
    for item in lst:
        fr.write('{},{},"{}"\n'.format(item['type'],item['document'],item['onclick']))    
return lst

if name == ‘main’:
print(download())

Can you please help ASAP

Hi Abhilasha,

I have attached the workflow and I have commented out an if condition where there is no statement in the IF condition. Please find the attached workflow.
Main.xaml (6.9 KB)

Thanks a lot Rahul, needed a small confirmation- is UiPath only compatible with 32 bit python version?

The latest 2018.4 stable version supports Python 64 bit as well.

Hii rahul
I have a python script which is not giving any error when i run the code in cmd but when i have loaded it in uipath it is giving error failed to load python script.

Hi Saigiriraj,
Would you mind sharing your Python script?

CultivationFacilityScoreBreakdown.zip (430 Bytes)

Hi,

Attaching the workflow. Please get back if there are any issues.
Make sure the PDF file is at the same path.
And also, it would be advisable to pass the arguments into the Python script.
CultivationFacilityScoreBreakdown.zip (11.7 KB)

Thanks,
Rahul, P

Still same error and i am sending my pdf file too.CultivationFacilityScoreBreakdown.pdf (500.6 KB)

Hi Rahul,
Error is resolved but python script is unable to read pdf .I have given file name and that pdf is in same directory of xaml file and python script .PFA image of error occurred .

Thanks error