Invoke Python Method: Pipe is broken

Hi,
I’m trying to load a python script in my project when I called “Invoke python method” I’m getting pipe is broken error. Could someone help me on this

@VC365

Have a look below thread.

Hi @VC365,

Pipe is broken is a very abstract error in .net and C# and with minimal root cause. I have wasted a lot of time trying to find out why this happens without a concrete answer in the forums or in stackoverflow.

In my view, the amount of data being sent from one activity to another or one workflow to another throws “Pipe is broken.” error in UiPath. I suspect that your python code returns an object (json, og other object from python to .net) which is of a large size.

What is large?
In my tests on datatables, I found that if the datatable has more than 8000 rows and you are trying to send this to another workflow to process, then there are more chances for the “Pipe is broken” error in UiPath. In my case, I faced this error while finding unique values in a column within a large datatable (>8000 rows) and passed the datatable to another workflow. My solution was to not send the datatable to another workflow, but to process it right there within the process.

My suggestion:
Try/test by reducing the size of the object returned from Python by slicing the returned value. If that does not work please try and convert your return object to a json string.

In UiPath you can easily deserialize the return string from Python to get the json object and do any manipulations on it. Please refer this post to know how to do this from the python code and integrate this within UiPath: How to use permuation and combination in excel uipath - Help - UiPath Community Forum

Hope this gives you some ideas. Goodluck!

2 Likes

@jeevith thanks for the reply I have got to know the reason behind it my script takes a PDF file as input and converts checkboxes within it to yes and no and then coverts back to PDFS using some packages like tensonflow etc. May i know what can be the size to avoid pipe is broken error. BTW my script is not returning anything it just performs some actions on file and then places in specified path.
FYI here is one more query I posted related to my issue which was not resolved so I had to choose this option to convert them
How do I read a checkbox from a PDF using Document understanding framework.

Hi @VC365,

Interesting. So nothing is actually being passed as object to UiPath from the python script.

Ok can you tell us what are you returning from the python function? Would help if you paste your function’s code here.

def something(input):
   return  ??

If you are just returning a flag, it is interesting to see the Pipe is broken error occur in UiPath

@jeevith here is my main method
def main(*args):
start_time = datetime.now()

cbs = CheckBoxSolver(template_path,input_pdf_path,output_pdf_directory,model_path)
cbs.convert_pdf_to_images()
cbs.replace_checkboxes_and_save_images()
cbs.write_to_pdf()

end_time = datetime.now()

print('Duration: {}'.format(end_time - start_time))

#configuration

output_pdf_directory = “./output”
model_path = r’./model/checkbox_classifier_model.hdf5’
template_path = r’./templates’

if name == “main”:
parser = argparse.ArgumentParser()
parser.add_argument(“–file_path”,help=‘Pdf Input File Path’)

args = parser.parse_args()

if args.file_path:
    input_pdf_path = args.file_path
    main(template_path,input_pdf_path,output_pdf_directory,model_path)
else:
    print("Pdf Input File Path Required...")

Hi @VC365 ,

Did you find any solution? I’m also getting the same error. I’m trying to extract data from PDF invoices.

Hi @VC365 and @sri_e,

I forgot to reply here.
From @VC365 I see that the return value is within a main function, which UiPath Invoke Python will not support.

  • What I suggest is you do all the processing using a helper function, call that helper function in another function with all required inputs.

  • Then call this function from UiPath Invoke Python.

The best way to get information back is using Json. So in short the function you call from UiPath should contain a return within it.

return (json_value) 

For example

def process_case(inputs):
    processedpdf = "your logic"
    return (processedpdf) 

def call_function_uipath(inputs):
    import json
    result = process_case(inputs)
    json_value = json.loads(result)
    return (json_value)

Thank you @jeevith for information. I will try and update back here.

anything happened afterwards?

@seetharaman , Nothing. I tried above steps but no luck. I’m using Batch file(.bat) to run Python script.

Thanks!
Sri

Hi @jeevith , i am also facing the similar issue. i have already tried using it in different metod, still not working. my code looks something like this -

def start(val1,val2,val3):
	directory=r''+val1
	pre_filename=r'\\'+val2
	post_filename=r'\\'+val3

	alldata=get_predata(directory+pre_filename)
	alldata=get_postdata(directory+post_filename,alldata)
	if write_data(alldata,directory):
		return 'completed'
	return False

I’m invoking the “start” method but getting broken pipe error.
Kindly help here.

@Robinnavinraj_S check this out.

@abhi3,

Can you share your workflow and your complete python code, so can able to sort out the issue.

Regards,
@90s_Developer

I face same issue when I am working on python and call into uipath script.

Setps need to follow these

  1. First drag python scope activity:-
    image
    In Path preparty you must paas your python install folder
    image
    b) in other propert like Target which operating system you are working like 64bit or 32bit according you can select.
    C) In Working Folder you must pass where your python script located.
  2. After you need to drag load python script
    image
    a) pass your python filepath in file property
    b) And create output variable
    image
    it will give output in python object
    you can also run direct python script in
    image
    if you want to call method then Use Invoke python Method
    image
    a) pass input variables in inputParameters
    b) pass your output variable of load python script activity into Instance.
    c) Name your python method paas into Name Property.
    d) create output variable in Result.
    After Drage : -
    Get python object Activity
    image
    image
    a) In pythonobject pass variable of Invoke Python Method activity.
    b) In typeArgument select what datatype you are convert.
    c) create output variable and it will work for you.
1 Like

Hi ,
Found the issue and corrected it.
I was using read function to read a file but since the file was too long it was throwing this error

with open(filename,'r+') as pre_file:
		raw_data=pre_file.read()
		pre_file.close()

It was resolved when I used readlines function instead -

with open(filename,'r+') as pre_file:
		raw_data=pre_file.readlines()
		pre_file.close()

Thanks for your time anyways,
Regards.

1 Like

@abhi3,

Great to hear this! If you’re issue is solved, kindly mark as a solution to the exact reply to whom does it fit. So that this thread will get closed.

Regards,
@90s_Developer

1 Like

I’m facing this issue on Users Machine, however it executes well on my system.

Below is the code I’m trying to execute.


import sys
from fuzzywuzzy import fuzz

def DescriptionMatch(str1, str2):
strPercentage= str(fuzz.token_set_ratio(str1, str2))
return strPercentage


Hi, I am getting the same error too. In my case it’s similar to what you just explained. I am comparing 2 strings for their similarity and the script is returning a json containg 2 strings and their similarity percentage.

This is the script I am using, what am I missing? I m actually calling the function partial_match within UiPath.

import pandas as pd
from difflib import SequenceMatcher
#import time
def partial_match(file1,sheet1,file2,sheet2,threshold):
    #start_time = time.time()
    df = pd.DataFrame()
    rows = []
    exc1 = pd.read_excel(file1,sheet1)
    exc2 = pd.read_excel(file2,sheet2)
    for index, row in exc1.iterrows():
    
        a = row["NameAlias_WholeName"]
        for index, row2 in exc2.iterrows():
            b = row2["First Name"]
            simmilarity = round(SequenceMatcher(None,a,b).ratio()*100,2)
            simmilarity = int(simmilarity)
            if simmilarity > int(threshold):
                #print(a," ",b," ",simmilarity,"%")
                rows.append({'Col 1': a,'Col 2':b,'Col 3':simmilarity})     

    df = pd.concat([df, pd.DataFrame(rows)], axis=0, ignore_index=True)
    return df.to_json(orient='records')

@jeevith Hi Jeevith. A quick update. The issue was happening due to the below:

  1. One of the dependencies for the python project was missing. The code was working fine without any issue in Spyder IDE, but when I switched to Python’s IDLE I was getting error (in my case openpyxl was not installed). I Installed it and then it worked.

  2. Also, I tested and you can convert dataframe to a json and get it as an output via UiPath. But I didn’t opted it, I went with saving the dataframe to a csv file instead.

I recommend using IDLE to test the code, if it works in IDLE it should work in UiPath also.

1 Like