Invoke Python Method: Pipe is broken

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

Hi @amithvs,

I have wasted a lot of hours as I said before trying to understand Pipe is broken error and I have chosen to move away from the Python Scope Activity. My other two fallbacks are Invoke PowerShell Activity and Start Process Activity. Sadly the Invoke PowerShell activity is currently broken in Windows projects (UiPath Community 2022.12 Release - #41 by jeevith)

So the Start Process activity is the only option I can see working using standard UiPath activities. It has a way to call a command asynchronously or synchronously, which is great. Meaning we can let the Start Process complete the command and only then will the other activities in the sequence carry on.

  1. Start Process (python script and its arguments → save to a .csv)
  2. Read the csv file in UiPath
  3. If needed delete the csv as a cleanup

Here is requirements.txt file :
requirements.txt (646 Bytes)
(you can install all of the dependencies to your system python installation by using pip install -r requirements.txt)

The Start Process activity uses Windows Command Prompt to execute the script and uses the python path from environment variables.

My implementation looks like this using Polars

import polars as pl
from fuzzywuzzy import fuzz
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("ThresholdValue", help="The threshold similarity value to be checked", type=str)
parser.add_argument("Input1", help="The first excel file path", type=str)
parser.add_argument("SheetName1", help="The sheet name for Input1", type=str)
parser.add_argument("Input2", help="The second excel file path", type=str)
parser.add_argument("SheetName2", help="The sheet name for Input2", type=str)
args = parser.parse_args()

# Helper functions
def ReadData(FilePath:str, SheetName:str): 
    datatable = pl.read_excel(file=FilePath, sheet_name=SheetName)
    return datatable

def FuzzRatio(FirstName,AliasName):
    ratio = fuzz.ratio(FirstName,AliasName)
    return ratio

def CheckThreshold(SimilarityValue, ThresholdValue):
    return int(SimilarityValue) > ThresholdValue
    


# Polars dataframe queries
def CalculateSimilarity(dataF)-> pl.DataFrame:
    """
    Calculate the similarity ratio and return a dataframe
    """
    result = dataF.with_columns( [
        pl.struct(["First Name", "NameAlias_WholeName"])
        .apply(lambda x: FuzzRatio(x["First Name"], x["NameAlias_WholeName"])).alias("StringSimilarity")])
    return result

def FilterRows(dataF, Thresholdvalue)-> pl.DataFrame:
    """
    Filter data rows where the similarity is over the threshold 
    """
    result = dataF.with_columns([
        pl.struct(["StringSimilarity"])
        .apply(lambda x: CheckThreshold(x["StringSimilarity"], Thresholdvalue)).alias("OverThreshold")])
    result = result.filter(
        (pl.col("OverThreshold") == True))
    return result

def ProcessData(DataF:pl.DataFrame, Thresholdvalue:int)->pl.DataFrame:
    """
    Performs all tasks in the pipeline and return json string
    """                   
    ProcessPipeline = (DataF
    .pipe(CalculateSimilarity)
    .pipe(FilterRows, Thresholdvalue)
    )
    return ProcessPipeline


if __name__ == "__main__":
    # Ingest Data
    input1 = ReadData(args.Input1, args.SheetName1 )
    input2 = ReadData(args.Input2, args.SheetName2)
    CombinedInput_dataframe = pl.concat([input1,input2,],how="horizontal")
    
    resultdf = ProcessData(CombinedInput_dataframe, int(args.ThresholdValue))
    resultdf.write_csv("result.csv")  # this csv can be later accessed by UiPath

Here is the project folder PolarsDataframeinUiPath.zip (13.4 KB)

2 Likes

Thanks for the detailed explanation. Much appreciated! I will go through it.

I was also working with fuzzywuzzy, as it was giving better results compared to others. Only difference is I was using fuzz.token_sort_ratio to get the simmilarity ratio. This method was giving me the desired results.

Great work! Thanks a lot for your effort. Apologies, if I made you waste time on this.

Definitely not. Was motivated to learn Polars so thank you!

1 Like

I was facing the same issue. I fixed it by following the below steps:

  1. In the “Invoke Python Method” pass the InputParameters as: New List(Of Object) ({string variable}). Example: New List (Of Object) ({text}) where text is the string variable
  2. Refer the below merged screenshots

One possible reason for a “Pipe is broken” error which no-one else seems to have mentioned is a missing library in the python runtime environment. When trying to fix a Python Scope hanging up error, I changed the python.exe file used to run the code, and forgot to switch it back. This resulted in a “pipe is broken” error once the scope would again execute (with .NET 5.0 runtime). I am guessing if you are relying on a lot of libraries in the python code, it may be you are missing one on the computer trying to execute the code. I think it should give a more informative error message, but at least in Python Activities 1.4 you get just “Pipe is broken”.

Hello, I would like to add to this that, from my observations, whenever the Python script encounters an unhandled exception where it would terminate the flow, it would also trigger the UiPath Pipe is Broken error. I have noticed that, if you watch the immediate panel at the $exception variable it does show one layer of the Python error:

RemoteException wrapping System.AggregateException: One or more errors occurred.  ---> RemoteException wrapping System.InvalidOperationException: Error invoking Python method  ---> RemoteException wrapping System.InvalidOperationException: Python instantiation exception
Python Invoker program exception:
TypeError : can only concatenate str (not "AttributeError") to str

However, if you would try to extract it via the UiPath Try-Catch block, you would simply get this message.
image
This is the Catch workflow:

My question would then be, is there a reliable way to pull the actual unhandled error from inside the Py script, instead of the Pipe is broken message?

Hi Guys,

Might be late to this thread but even I faced the same issue. I was able to resolve this by lowering the python package ver to 1.3.0. Thought to share this here, might help someone in the future.

Cheers Dev

hi @jeevith , could you plz help me to solve issue related to run python in UiPath as i am facing many challenges to do that since long time . thx in advance

Hi @Bh_P,

You could write about your hurdle in a new post and the forum members /I can probably help you out.

Without understanding what your hurdle is, we can’t help much.

Could you follow this link I provided this issue solution here Can't run python script uipath - #5 by pawanrajpurohit

I was receving same issue for one of my python code.
I resolved this by giving path of my python exe installed in Anaconda env and downgrade the python package version to 1.3

Pipe is broken can be caused by anything wrong in the python. To figure out the problem, I run the script from command prompt, feeding it the same arguments (if any) that UiPath sends it.

One time a simple “sys.exit()” statement caused Pipe is broken.

This seems like they broke something in the newer packages. I have a script I was testing invoking from UiPath running on Python 3.8. Just running the file outside of UiPath worked fine. I first tried the newest package 1.7.1 which was giving me the pipe error no matter what I did. Per some comments in this thread I downgraded to 1.3.0 and that invoked successfully.

Hi @TheCraftyCoder

Could you please share a minimum version of the script that is causing this issue for you?