Passing arguments to Python

I’m confused,how are you running it? If you run this from within an IDE without using any arguments then you won’t have any to show.
I recommend creating a python file with this script and then call it from the command line with arguments, like myscript.py “This is a test message”

Hi,

It is running now for me. Thanks for your patience in explaining this for me.

But when I try to call this python script in UiPath, it is throwing Load Python Script error.

Are you calling a python script or the Jupyter notebook from UiPath?
If you create a python file (.py) like the one I used and call it from the activity it will work as expected.

I am calling python script (Categories1.py) from UiPath.

It is working now. The version of the Python I am using is 2.7 but I gave it as 3.6 and mentioned it as 64 bit instead 32 bit. After correcting it, it is working fine.

I wanted to know how to pass generic value to the python code. In my .xaml file, I am passing SubjectMessage as an input parameter. But finally in the message box, instead of subject line, I am getting SubjectMessage displayed. I have attached the screenshot below. Can you please help.

image

Hi,

The above example you provided is for integer value. How about the variable of Generic variable type? How to pass this variable to python code via input parameter property of the invoke Python Method?

I would recommend you don’t use Generic types, in my experience string, integers and lists work OK but I’m not sure generic is supported.

With the SubjectMessage are you passing {“SubjectMessage”} by accident when it should be {SubjectMessage}. Seems you are passing a constant string rather than a variable.

Hi Bobpeers,

it is working fine for me. I am able to pass the subject as well as body to the python code and retrieve it back. Only thing is i need to assign this generic value to another variable of type string. Thanks for your patience as well explaining me in detail.

Now I am focusing on sending email content with another variables (2 variables as input) to html page.

Can you guide me on the activities what needs to be called as well the properties that needs to be taken care for those activities?

Hi Bobpeers,

The workflow is working fine for me. When I run the same workflow in a different system, I am ending up with Load Python Script error. I checked all the configurations. It looks the same as it is in my laptop. Can you help?

Regards,

Prameelaj

Hi Bob

Just curious, If it supports I Python Notebooks as well ?

Problem statement is passing an input string to an I Python Notebook which is running ML Algorithms under the hood to classify input variable and label string to a particular category. Output variable (Classified string) is subsequently triggering a UI Path Workflow. Thanks !

Hi,

you need to convert the notebook to a plain python file for it to work using nbconvert, Using as a command line tool — nbconvert 7.1.0 documentation

Hello,

Is datatable able to be passed as argument ?

We need to use it with pandas ?

Regards,
Diogo Nunes

@bobpeers pls send any sample file passing list object to python method

@bobpeers
pythonD1 pythonD2 PythonD3 pythonD4 tolearnPy.zip (15.5 KB)

Hi, I’m trying to pass a file path as a parameter to the python script in invoke python method. But it says error invoking python method.
Any help is appreciated. Thank you

Hi @sandhya.b

Welcome to our UiPath Forum! :slight_smile:

Maybe this tutorial will help you:

It contains a very simple guide with screenshots and steps to follow on how to use Python scripting in UiPath Studio :slight_smile:

2 Likes

Thank you so much for the response…:blush:

1 Like

Subject : function with multiple parameters are not getting executed through python scope whereas when i use the same function in IDLE it is working perfectly fine.

from the above post,
Point 1) i need to add import sys; package
Point 2) how to pass the parameter for my fucntion which involves all three parameters(two path and one string)

Function Name : ExtractHtml, PFB the function input parameters

print(
ExtractHtml(“\\deda1vfiler13\RPA_DEVELOPMENT\DevGov\Bot\Data\Input\Batch-25-09-2022\Batch-08-59-48\InputfilePOCFinal_Copy - Copy.docx”,
“143”,
“\\deda1vfiler13\RPA_DEVELOPMENT\DevGov\Bot\Data\Temp\Batch-25-09-2022\Batch-08-59-48”)
)

Please help on this!

Hello @soundappan.prabu
As you have mentioned its working in IDE, can you please confirm you have passed the arguments to the python script in UiPath?

Also please share the error if any.

Thanks

No, through python IDLE only! A simple function working fine with python scope of UIpath! when passing one than one parameter then the problem rises.!

20.10.6+Branch.master.Sha.37657ef79003ea8751ac4efb35736eeeace8b2ce

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]]: com_error : (-2147352567, ‘Exception occurred.’, (0, ‘Microsoft Word’, ‘Sorry, we couldn't find your file. Was it moved, renamed, or deleted?\r (“C:\…\InputfilePOCFinal_Copy - Cop…”)’, ‘wdmain11.chm’, 24654, -2146823114), 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.InvokeMethod(Guid instance, String method, IEnumerable1 args) at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass14_0.<InvokeMethod>b__0() at System.Threading.Tasks.Task1.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.d__16.MoveNext()
— End of inner exception stack trace —
at UiPath.Python.Activities.InvokeMethod.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)

Hi,

How do i pass this as arguments in studio, could you please help?

from translate import Translator
#from googletrans import Translator

def languageTranslator(userData):
translator= Translator(from_lang=“bulgarian”, to_lang=userData.get(‘language’))
translatedText= translator.translate(userData.get(‘text’))
#print("rsult: " + translatedText)
return(translatedText)