Hi,
I have a python script that will return a list of strings. What option should i choose for to convert the python object to .net type and in general is there a thumb of rule which type to choose to go with which python type ?
Thank you!
Hi,
I have a python script that will return a list of strings. What option should i choose for to convert the python object to .net type and in general is there a thumb of rule which type to choose to go with which python type ?
Thank you!
Hi @ivory_le
First you use Invoke Python method activity to run python code. The result of the invoked method, stored in a PythonObject
variable. Can be further processed using the Get Python Object activity and converted to a .NET datatype.
Hi I used Get Python Object but im encountering this error
in Test.xaml
at InvokeMethod “Invoke Python Method”
at Sequence “Do”
at PythonScope “Python Scope”
at Sequence “Test”
at Test “Test”
System.AggregateException: One or more errors occurred. (Error invoking Python method) —> System.InvalidOperationException: Error invoking Python method —> System.NullReferenceException: Object reference not set to an instance of an object. at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass15_0.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
— End of stack trace from previous location —
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
— End of stack trace from previous location —
at UiPath.Python.Activities.InvokeMethod.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
— End of inner exception stack trace —
at UiPath.Python.Activities.InvokeMethod.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
— End of inner exception stack trace —
at UiPath.Shared.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
my script return a string and i want to convert it into a string type
side quetion: if i have a list of strings returned what should i convert to in .net type
Hi @ivory_le
Refer below post and see if points mentioned helps. Also could you share the screenshot of your workflow? what all activities you are using?
i ran my script in code editor and it worked and it returned a single string
here is my get python object set up
You are getting error on which activity is it on python scope then check python path you configured correctly?
This part suggests that issue is with calling python method. looks like the variable you are using is null.
could you run this workflow in debug mode and see what activity it is failing and from local panel, verify that variables have values assigned?
I’m getting this error:
error CS0246: The type or namespace name ‘GlobalVariablesNamespace’ could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name ‘GlobalConstantsNamespace’ could not be found (are you missing a using directive or an assembly reference?)
Can you share your python script?
import pandas as pd
def get_bot():
bot_file_path = r".some_file_path"
# Load the Excel file into a DataFrame
df_bot_table = pd.read_excel(bot_file_path)
# Define the conditions for filtering
conditions = (
(df_bot_table["a"] == True) &
(df_bot_table["b"] == 1)
)
filtered_df = df_bot_table[conditions]
return filtered_df["Prod"].tolist()[0]
sorry i have to change some of the name but this script interact with another xlsx file and return a string
Hi this is my issue now it said i can’t convert to a string
in Test.xaml
at GetObject`1 “Get Python Object”
at Sequence “Do”
at PythonScope “Python Scope”
at Sequence “Test”
at Test “Test”
System.InvalidOperationException: Error converting Python object —> System.InvalidOperationException: Python instantiation exception
Python Invoker program exception:
‘module’ value cannot be converted to System.String
at UiPath.Shared.Service.PythonResponse.ThrowExceptionIfNeeded()
at UiPath.Python.Service.PythonProxy.Convert(Guid obj, String t)
at UiPath.Python.Impl.OutOfProcessEngine.Convert(PythonObject obj, Type t)
at UiPath.Python.Activities.GetObject1.Execute(CodeActivityContext context) --- End of inner exception stack trace --- at UiPath.Python.Activities.GetObject
1.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
you are returning a list of strings, right? if yes, in get python object, please set type argument as array of string
i just returning a string right now. it said that the python can’t find my script function right now. i’m using our example from invoking a python method with add function and it said that they can’t find my module attribuate “add” do you know what might be the reason ?