Integrate Python script with Uipath

Hi all, I am trying to get required output by invoking Python script in Uipath…I have used Python scope, Load Python script, Invoke Python method, Get python Object but unable to get the result…I tried with 2 lines code and got the result but when I use my actual code…It does not work…

Can you post the error you are getting @Rajnish?

And are you trying to return the valid data object from python code?

1 Like

Thank you for your quick response…I am attaching work flow for your reference…Main.xaml (7.1 KB)

Please post the error and python code @Rajnish

1 Like

@HareeshMR I am able to execute the code but in result it gives nothing…here is the code

def text_difference(text1_path,text2_path):
with open(text1_path) as a, open(text2_path) as b:
text1=a.readlines()
text2=b.readlines()
counter = 1
for (line1,line2) in zip(text1,text2):
if line1 in line2:
pass
if line1 not in line2:
line_difference = counter
line_difference_1 = line1
diff1=line1.split()
diff2=line2.split()
index = 1
for (a,b) in zip(diff1,diff2):
if a != b:
word_difference = index
word_difference= a
index +=1
counter += 1
return line_difference,line_difference_1,word_difference,word_difference_1
##path1 = “C:\Users\ryadav\Desktop\Python result\File 1.txt”
##path2 = “C:\Users\ryadav\Desktop\Python result\File 2.txt”
##text_difference(path1,path2)

Is there any difference between these files?

Yes, it’s there.

Can you explain how you are trying to retrieve the results from the code @Rajnish?

1 Like

Python code will find the unique data and using Uipath we can write the result in .txt file

Can you check whether you are getting results from the python code @Rajnish? Just after Get Python Object activity with the variable you gave in Get Python Object.

Why don’t you write the values directly into text file in the python code itself :slight_smile:

I am getting the output in .txt file but not 100% accurate…"Why don’t you write the values directly into text file in the python code itself "…I dint get this sentence…Could you please elaborate??

I mean instead of returning the values from python code and writing them into text file, you can write the values directly in to text file in the python code itself right? @Rajnish

what you mean by 100% accuracy :slight_smile: ?, can you please explain

Yes, you are absolutely right that we can get the result directly in Python itself…But here in organization they want this using Uipath…100% accuracy means i am getting matched and unmatched both the data in .txt file…by the way I am trying to integrate new Python code with Uipath but it’s getting stucked in ‘Load python script’ any idea???

Can you post the error you are getting?

19.8.0+Branch.master.Sha.680d3a6b9a242ff3a0f9a32b7bf3faba605524aa

Source: Load Python Script

Message: Error loading Python script

Exception Type: System.InvalidOperationException

RemoteException wrapping System.InvalidOperationException: Error loading Python script —> RemoteException wrapping System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: SyntaxError : ("(unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: malformed \N character escape", (‘none’, 11, 28, None))

Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object ins, Object outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at UiPath.Python.Service.IPythonService.LoadScript(String code)
at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass11_0.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at UiPath.Python.Activities.LoadScript.d__12.MoveNext()
— End of inner exception stack trace —
at UiPath.Python.Activities.LoadScript.d__12.MoveNext()
— End of stack trace from previous location where exception was thrown —
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Here is the error @Rajnish

Are you providing path of a file? Then send the path with double back slashes

You mean in Uipath workflow or Python script???

python script

Let me give a try

Same issue