Getting error when using python activities in uipath

@Yoichi @Vibhor.Shrivastava @Dilip_Wakdikar_1996 @RAKESH_KUMAR_BEHERA . Am use python activities in UiPath. But getting error that “Pipe is broken” at invoke python method. If i use simple code like “hello world” then it works fine. But when i use code like detect face and all then getting error.

Could you please share your code?
In mean time you can actually use invoke PowerShell command to execute the python code.

1 Like

import requests

http_url = ‘https://api-us.faceplusplus.com/facepp/v3/detect
key = ApiKey
secret = APiSecret
filepath = r"image1.jpg"

Read the file content

with open(filepath, ‘rb’) as file:
image_content = file.read()

Create the payload data

payload = {
‘api_key’: key,
‘api_secret’: secret,
}

Make the POST request

try:
response = requests.post(http_url, data=payload, files={‘image_file’: image_content}, timeout=5)
response.raise_for_status()
print(response.text)
except requests.exceptions.RequestException as e:
print(e)

this is my code and i want to pass images as input

I was wondering, why we need to invoke python code for this. We can simply download UiPath.Web.Activities package from the manage package and from that pack you use HTTP request activity to hit an Api call. That would be the simplest approach.

1 Like

Yes you are right. I just give you the example of this. My actual requirement is that if we want to use python code in UiPath. And we have to pass the input then every time it gives like this error.
I also a try a code in which we split pdf into multiple pdf’s . Then am occuring the same

import os
from PyPDF2 import PdfReader, PdfWriter

Set the input file name

input_file = ‘Sample 3.pdf’

folder_Name = os.path.splitext(input_file)[0]

Set variable that the number of pages per output PDF file

pages_per_file = 1

Create the output folder as that of pdf name

if not os.path.exists(folder_Name):
os.mkdir(folder_Name)

now open the respective pdf fil and read it after reading store it in another variable.

with open(input_file, ‘rb’) as infile:
pdf_reader = PdfReader(infile)

# using for loop Iterate through the pages of the input PDF file
for page_num in range(len(pdf_reader.pages)):
    
    # It Create a new PDF file for every 'pages_per_file' number of pages
    if page_num % pages_per_file == 0:
        
        # If this is not the first file, close the previous one
        if 'outfile' in locals():
            outfile.close()
            
        # Create a new output PDF file
        output_file = folder_Name+'/{}_{}.pdf'.format(os.path.splitext(input_file)[0], page_num // pages_per_file + 1)
        outfile = open(output_file, 'wb')
        
        # Create a new PDF writer object for the output file
        pdf_writer = PdfWriter()

    # Get the current page of the input PDF file
    page = pdf_reader.pages[page_num]
    # Add the page to the current output PDF file
    pdf_writer.add_page(page)

    # If we have reached the end of a 'pages_per_file' number of pages, save the output file and start a new one
    if (page_num + 1) % pages_per_file == 0:
        pdf_writer.write(outfile)

# If there are any remaining pages, save them to a new output file
if 'outfile' in locals():
    pdf_writer.write(outfile)
    outfile.close()

this is that code. I don’t get any activity in UiPath to split pdf to multiple pdf’s

I understand your pain point. I’ll try to execute this code in python and will revert back to you.

However, We have an activity pack which you can use to split the Pdf into multiple pdfs. You can download UiPath.Pdf.Activities and use Extract pdf page range and it should work fine!

Yes please try to do this python code and tell me how we can do this.

But by using this “Extract PDF page range” activity we only get pdf fro specific range. My requirement is that if we have 100 pages in a pdf then i want each page pdf (means 100 pdf’s).

Thanks for your concern.

Aside the ongoing check on python kindly note

in combination of get PDF Page count, we can do the splitting within a loop implementing it within essential activities

As Peter suggested you should be able to develop the logic using the Extract PDF range and do it.

However, I was able to run the python code for split pdf. Actually the python code you shared has bugs. And I have fixed it. please find the attached code

Let me know if you need more assistance.

Note:- Make sure you are able to import the PdfReader and PdfWriter from PyPDF2

Sequence.xaml (11.0 KB)
SplitPdf.zip (663 Bytes)

1 Like


Thanku.
But I use the same code that you provide but still getting error. Also attach the files if am wrong then correct me
Sequencefrom.xaml (11.0 KB)

Thanks peter. I am trying to create this type of logic. But also want to do this with python.

Did you verify if you are able to import PdfReader and PdfWriter not from UiPath Studio but from command prompt or Python IDLE.
Also, what version of python are you using?

Yes yes. Code is working fine in my cmd . Am using python 3.6 version. Am also do the same thing with 3.9. But still this occurs "Pipe is broken "
Please give me the solution

@Dilip_Wakdikar_1996 You get any solution ?

Hi @Vivek_Sharma

I was able to get things working, but your original XAML file was missing this property:
image

Like so:
Library path: "C:\Users\maciej.kuzmicz\AppData\Local\Programs\Python\Python311\python311.dll"

Path:
"C:\Users\maciej.kuzmicz\AppData\Local\Programs\Python\Python311"

With this change, the above script worked just fine.

One remark though - I am using the UiPath.Python.Activities 1.7.1 and Python 3.11. I also had to make sure to install python -m pip install PyPDF2 for the specific Python version that I wanted to run.

Hi @loginerror ,
I tried but did not any thing . might be i am missing something. If everything is fine then can you please share xmal file with me. By the way thanks for response and showing interest in the post.

Is it possible for you to try the same Python 3.11 version as I’ve tested above?

If not, what is the version od Python that you are testing with?