Pass List<String> as an argument to Python script from Studio

Hello all,

Context: I am using a python script which loops through list of sheets in an excel file to carry out list of checks.
Now, list of sheets & checks will vary based on user’s choice collected through forms.

Problem: I am passing 2 strings (paths) and 2 lists( sheet_list & checks_list) as arguments to python script. But it fails every time at Invoke Python method saying, “One or more errors occurred.”

Python script independently through MS Vscode is running as expected.

Please guide on how to pass 2 string and 2 list arguments to the script.

The image displays the UiPath activity settings for invoking a Python method with specified input parameters, instance, method name, and output result. (Captioned by AI)

Need urgent help here !!

Hi @Shubham_Tiwari , my first query would be re the need to use Python. What does Python do in the file?

@Shubham_Tiwari

to know the error run in debug and then open locals panel from where you can check the exception details

cheers

Hi @Shubham_Tiwari

Which version of Python activity package is it? And which Studio project type (legacy, windows)?

Could you please try:

Package is 1.8.1 and Legacy project.

That is another issue, Anil. Output python object ( result variable ) from Get Python object every time gives error stating, Cannot convert Python object. I tried by using variables of type data table, object, string.
For now, my python script will only return exception in case it occurs inside the script and there is no output as such.

Script takes list of sheets as input. Go through all cells of those sheets and perform some basic checks such as if cell contains negative formula, complex formula, only formula, hardcoded value etc. Which checks to perform is also expected as input as a list.
Later, script writes all identified cells with sheet names, value and formula into an excel file.

@Shubham_Tiwari

if there is no output then no need to use the convert activity only

cheers

but how to get exception details out from script then?

New List(Of Object)({}), didn’t help. :frowning:

@Shubham_Tiwari

are you using try catch in python?

if yes then assign it to the output variable or return as a string and that can be converted

if not the exception will be anyways bubbling to studio as well in innerexception

cheers

Also, just to confirm. My code looks something like this:

def performExcelOps():

… lines of codes

def main(inputPath, outputPath, sheetNamesList = , checkNamesList = ):

def performExcelOps()



.
.
.

if name == “main”:
main ()

Am I missing something here, in terms of calling main function inside the script or it is not needed while invoking from UiPath?

@Shubham_Tiwari

main call will be done by UiPath you need not call in the script

also i dont see any try catch…as mentione dif you want to get exception message then catch it and assign as string and return

cheers

Try catch is present, only in above sample I did not add.

Got the error details btw, @loginerror

@Shubham_Tiwari

it is unable to serialize list…you can pass it as comma separated string and convert to list in code

cheers

1 Like

Yes, from this and other bot what I have understood is passing any Collection (List, Datatable, etc) gives error whereas arguments Int, String are compatible with the invoke python method activity but not collections.

I modified the code to write list in text file from UiPath which will be read by python hence removing need to list argument keeping only String arguments. This is working.

Need update in Python activity probably to overcome this issue if I am correct to understand it.

Thanks Anil for your time

2 Likes

Valid workaround.

As to the issue, I finally found some time to experiment a bit and I was able to make it work with a string and an array of strings with a sample script:

It would seem like you can add arrays to the list of supported conversions.

But indeed, even in this sample, I return the dictionary as a string, because it cannot handle the conversion between the python dict and .net Dictionary (as another example of the limits).

We will have a look what can be done here, but for anyone who is really impatient, the Python activities code can be viewed over here:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.