I have a problem which I am facing that I cant solve. I have a python script that converts PDF into CSV files. When I run the script in Spyder, it works perfectly.
Basically, within a Python Scope, I am using ‘Load Python Script’ (No error) > Followed by Invoke Python Script (Error occurs here). I also tried using the ‘Run Python Script’.
I have attached the python script here for the community’s easy reference.
I have simplified the script and added screenshot to illustrate better. Essentially once I comment out the targetPath = filedialog.askopenfilename... statement, it will work (else, error is thrown at Invoke Python Method). Any idea why ? it seems like uipath was unable to read the filedialog methods to me.
Yup, i saw it, to share, for simple python files, they work (i.e. no errors). But I realised for instance in my case, If i remove all the codes in my script less the import statements, they will work. However, when I add in the details such as the below, the error will come.
root = tk.Tk()
root.withdraw()
targetPath = filedialog.askopenfilename(title="Select the pdf file to convert!")
outputPath = filedialog.askdirectory(title="Select location you wish to save output result to!")
My objective is to basically just run the python file using UiPath. The python file which I shared can be tested too and it works fine on Spyder / running via command prompt.
My python script written inside expression editor of the Load Python Script Activity
"
def hello():
import tabula as tab
from tkinter import filedialog
from tkinter import messagebox
from datetime import datetime
#the below statement will throw an error in UiPath. It works when I run it via cmd / spyder
#what it does is that it will prompt user to select file to upload.
targetPath = filedialog.askopenfilename(title='Select the pdf file to convert!')
return 'Hi'
"
Logs
19.10.4+Branch.support-v2019.10.Sha.fe819a658cad0585a64d2f8af94fad5c30b8d122
Source: Invoke Python Method
Message: One or more errors occurred.
Exception Type: System.AggregateException
RemoteException wrapping System.AggregateException: One or more errors occurred. ---> RemoteException wrapping System.InvalidOperationException: Error invoking Python method ---> RemoteException wrapping System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: IndexError : list index out of range
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.InvokeMethod(Guid instance, String method, IEnumerable`1 args)
at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass14_0.<InvokeMethod>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.InvokeMethod.<ExecuteAsync>d__16.MoveNext()
--- End of inner exception stack trace ---
at UiPath.Python.Activities.InvokeMethod.<ExecuteAsync>d__16.MoveNext()
--- End of inner exception stack trace ---
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)
Essentially, I am trying to run a python script in UiPath. I have placed a ‘Run Python Script’ within a ‘Python Scope’ activity. In the ‘Run Python Script’, I have placed the following simplified code which uses advance features of python.
import tabula as tab
from tkinter import filedialog
from tkinter import messagebox
from datetime import datetime
#the below statement will throw an error in UiPath. It works when I run it via cmd / spyder
#what it does is that it will prompt user to select file to upload.
targetPath = filedialog.askopenfilename(title='Select the pdf file to convert!')