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!

@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.

@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