Invoke python method activity is not working

Hi Team,

While executing the python code through UiPath i am getting below error for Invoke python method activity.
“Invoke Python Method: One or more errors occurred”
Please help me how to resolve issue.
@ashokkarale

Can you share the screenshot of the code?

Python scope and load python script activities are working fine only Invoke Python Method activity throwing error

@Smitesh_Aher2

  1. First check if the python code file is running as expected or not
  2. To know the error you can open locals panel in debug mode and check the complete error

Cheers

Just let me know what values should i put in the properties panel of Invoke Python Method?
image

When you are loading the script, then save the result in a variable which will be of type Python Object.

Then use the variable in the invoke where it is written instance.


InputParams: you need to pass the parameters in the order.
Instance: Python Object, the output of the Load Python Script.
Name: Method Name

Feel free to share py script if it doesn’t work.

import os
from PyPDF2 import PdfReader, PdfWriter

def write_pdf_writer_to_file(pdf_writer, base_filename, counter):
os.makedirs(output_folder, exist_ok=True)
output_filename = os.path.join(‘output’, f’{base_filename}part{counter}.pdf’)
with open(output_filename, ‘wb’) as out:
pdf_writer.write(out)
print(‘Created:’, output_filename)
return output_filename

def pdf_splitter(path, size_limit_mb=32):
fname = os.path.splitext(os.path.basename(path))[0]
pdf = PdfReader(path)
counter = 1
pages_to_add =
for page in pdf.pages:
pages_to_add.append(page)
pdf_writer = PdfWriter()
for page_to_add in pages_to_add:
pdf_writer.add_page(page_to_add)
temp_filename = write_pdf_writer_to_file(pdf_writer, fname, counter)

    if os.path.getsize(temp_filename) > size_limit_mb * 1024 * 1024:
        # If the file size exceeds the limit, remove the last page from the list and save the file
        pages_to_add.pop() # Remove the last page from the list
        if pages_to_add: # If there are still pages left
            # Write the current list of pages to a file, excluding the last one that caused overflow
            pdf_writer = PdfWriter()
            for page_to_add in pages_to_add:
                pdf_writer.add_page(page_to_add)
            write_pdf_writer_to_file(pdf_writer, fname, counter)
            counter += 1
        # Reset the list of pages to add with only the last page
        pages_to_add = [page]
# Save any remaining pages in the last PDF part
if pages_to_add:
    pdf_writer = PdfWriter()
    for page_to_add in pages_to_add:
        pdf_writer.add_page(page_to_add)
    write_pdf_writer_to_file(pdf_writer, fname, counter)

filename = “100MB-TESTFILE.ORG.pdf”
output_folder = “output/”
pdf_splitter(os.path.join(filename))

def process_folder(folder_path):

for filename in os.listdir(folder_path):

if filename.endswith(‘.pdf’):

pdf_splitter(os.path.join(folder_path, filename))

if name == ‘main’:

input_folder = ‘input/’

process_folder(input_folder)

has context menu

Please let me know what value should i enter value in inputParameters field and in the Name field?
@arpan , @ashokkarale, @Yoichi

@Smitesh_Aher2

can you send the py file…if all these linked are there then it should not invoke the process…liekt his should not be ther pdf_splitter(os.path.join(folder_path, filename))

also in parameters you need to pass New Object() {"Path To File Here"}

cheers