# Invoke python method activity is not working

**URL:** <https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000>\
**Category:** Studio\
**Tags:** activities-panel, question, studio, python, activities\
**Created:** [September 5, 2024, 6:14pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000 "2024-09-05T18:14:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Smitesh\_Aher2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/smitesh_aher2/32/400665_2.png) [@Smitesh\_Aher2](https://forum.uipath.com/u/Smitesh_Aher2)\
**Post date:** [September 5, 2024, 6:14pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/1 "2024-09-05T18:14:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aravindbalineni123](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aravindbalineni123](https://forum.uipath.com/u/aravindbalineni123)\
**Post date:** [September 5, 2024, 6:27pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/2 "2024-09-05T18:27:10Z")

</div>

> [@Smitesh\_Aher2](#):
>
> Invoke Python Method: One or more errors occurred”

Can you share the screenshot of the code?

---

<div class="post-metadata">

**Author:** ![Smitesh\_Aher2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/smitesh_aher2/32/400665_2.png) [@Smitesh\_Aher2](https://forum.uipath.com/u/Smitesh_Aher2)\
**Post date:** [September 5, 2024, 6:31pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/3 "2024-09-05T18:31:06Z")

</div>

![image](https://global.discourse-cdn.com/uipath/original/4X/b/7/2/b72376dd13bd0f4bc6a65fa5065463165c68e4cc.png)

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

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [September 5, 2024, 6:43pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/4 "2024-09-05T18:43:23Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![Smitesh\_Aher2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/smitesh_aher2/32/400665_2.png) [@Smitesh\_Aher2](https://forum.uipath.com/u/Smitesh_Aher2)\
**Post date:** [September 5, 2024, 6:46pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/5 "2024-09-05T18:46:36Z")

</div>

Just let me know what values should i put in the properties panel of Invoke Python Method?  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/2/a/1/2a1af9a55e4a7770241e8f97b73ddabd2515e583.png)

---

<div class="post-metadata">

**Author:** ![lashie](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lashie/32/409055_2.png) [@lashie](https://forum.uipath.com/u/lashie)\
**Post date:** [September 5, 2024, 7:38pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/7 "2024-09-05T19:38:51Z")

</div>

> [@aravindbalineni123](#):
>
> screenshot of the code?

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.

 ![The image displays the properties panel for a UiPath activity 'Invoke Python Method,' with input parameters, instance, and method name set, and a result variable defined in the output. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/e/d/8/ed8179fd45f7e66797ed738f445a05783b875b25.png)  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/8/3/6832e261c50370abc5cf095594ac89930253f390.png)

---

<div class="post-metadata">

**Author:** ![aravindbalineni123](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@aravindbalineni123](https://forum.uipath.com/u/aravindbalineni123)\
**Post date:** [September 6, 2024, 3:55am UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/8 "2024-09-06T03:55:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Smitesh\_Aher2](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/smitesh_aher2/32/400665_2.png) [@Smitesh\_Aher2](https://forum.uipath.com/u/Smitesh_Aher2)\
**Post date:** [September 6, 2024, 9:09am UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/10 "2024-09-06T09:09:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anil\_G](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anil_g/32/524291_2.png) [@Anil\_G](https://forum.uipath.com/u/Anil_G)\
**Post date:** [September 6, 2024, 6:12pm UTC](https://forum.uipath.com/t/invoke-python-method-activity-is-not-working/765000/11 "2024-09-06T18:12:03Z")

</div>

@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
