Error : Invoke Python Method

Got this error in Invoke python method

hi @Sukanya_Dutta

Appreciate if you can share the error message as well as the Python Code. thanks.

Error message → “Invoke python method : One or more errors occurred”

Hello, from the available picture I can see the following problems:

  • InputData of type DataTable is null
  • InputString is null
  • The type of InputString is Int32, maybe should be String
  • The PyOutput pbject of type PythonObject is not initialized
  • The Code property of the Python script is null

Please see first the following link, that may be useful:
Invoke Python Code UIPath

Hope it can help. Adrian

How to solve this problem?

Hello @Sukanya_Dutta

Please check the below video.

Thanks

Hello again.
Watching the tutorial, I see the Python Scope activity is important.
So all the related Python activities must be included in this Scope.
What can be more difficult, is to find the good working Python path.
On my computer, I can get the next Library Path for my user name:

string.Format("{0}\AppData\Local\Programs\Python\Python37-32\python37.dll", 
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))

So you don’t have to specify the full path to your user name.
This path may depend also on the current installed Python version.
A Python package must be installed prior to use any of the scripts.
Personally, I have tried with more Python versions, 3.2 and 3.7.
In Explorer I can open and edit a py file with an IDLE program.
Running a script in IDLE, or other editors is a good verification.
This ensures, that the script is correct, and doesn’t give errors.

Another common problem is how to pass the input arguments to script.
Setting a variable in the Python Scope, this can become visible to the script.
But a python script uses different techniques for passing input arguments.
The Invoke Python Script activity should have a list of the input arguments.
I also seen, from your picture, that you had built a list of input parameters.

I tried myself a script, that takes the path to a CSV file and reads it.
For a list argument, could be more difficult to be declared in Python.
Python is a programming language, having several specific syntax.
Take a look, at how the function, conditions and loops are written.
This script may look like this:

import sys
import csv
import os

def read_model(*args):
    pad = args[0]
    if (pad == ""): return
    if (not os.path.exists(pad)): return
    print(pad)
    csvfile = open(pad)
    reader = csv.reader(csvfile)
    for line in reader:
        print(line)
        str = line
    csvfile.close()
    return

read_model("./Model.csv")
#EOF

In my case, I didn’t have to use the Invoke Python Method.
Because this method can be also called from inside the script.
This read_model function doesn’t return anything.

But usually, a function must return the result of a method.
For other purpose, it needs maybe to return a sum of numbers.
The out result is a variable of type: UIPath.Python.PythonObject
For each variable you want to use, this must be declared first.
This is made in Data Manager palette, or by Create New Variable.

Hope it can help. Adrian

I have a problem. Please share how to deal this problem.
The error in “load python script activity” is: value cannot be null: parameter name: stream
In python code, that have no error. But when it use Invoke Python Method, then have that error.
Also, There was no error when working the loop to create ppt in python 6 times, but when working 36 times, the above error occurs.