Python activity error

Hey All,

I am also getting the JSON serialization exception:

Source: Newtonsoft.Json

Message: Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462.

Exception Type: JsonSerializationException

using Python 3.6.6 [MSC v.1900 32 bit (Intel)] on win32

Any luck with above error? experiencing the same. However, this occurs only for few scripts

How did you solve the problem?

hello,I have used your Python_Workflow.zip, but I still have an error.

An error has occured

Source: Newtonsoft.Json

Message: Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462.

Exception Type: JsonSerializationException

Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462. —> Newtonsoft.Json.JsonSerializationException: Could not load assembly ‘Python.Runtime’.
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.GetTypeFromTypeNameKey(TypeNameKey typeNameKey)
at Newtonsoft.Json.Utilities.ThreadSafeStore2.AddValue(TKey key) at Newtonsoft.Json.Utilities.ThreadSafeStore2.Get(TKey key)
at Newtonsoft.Json.Serialization.DefaultSerializationBinder.BindToType(String assemblyName, String typeName)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName)
— End of inner exception stack trace —
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolveTypeName(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, String qualifiedTypeName)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadMetadataProperties(JsonReader reader, Type& objectType, JsonContract& contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue, Object& newValue, String& id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type)
at System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
at System.Exception…ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
at Newtonsoft.Json.Serialization.JsonFormatterConverter.Convert(Object value, Type type)
at System.Runtime.Serialization.SerializationInfo.GetValue(String name, Type type)
at System.Exception…ctor(SerializationInfo info, StreamingContext context)
at System.AggregateException…ctor(SerializationInfo info, StreamingContext context)
at Void .ctor(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)(Object )
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateISerializable(JsonReader reader, JsonISerializableContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at UiPath.Shared.JsonParser.DeserializeObject[T](String jsonValue)
at UiPath.Models.UiPathDuplexProxy.<>c__DisplayClass18_0.b__0()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

Hey guys I had the same issue…bt when i made slight modification in my python code(just make sure that function definition starts with a tab under the function declaration) it worked pretty well!

I got the same error to, anyone solved it?

please check your python version as of now UiPath will work with only 32 bit

It worked when I tried to run a simple python script, but failed while try to run a script with pywin32, not sure if anything wrong there

For those stuck on the following error:

I took out all comments that used the triple single quote syntax (i.e. ''' comment here ''') and then my script could load. For example:

import subprocess

''' THIS COMMENT SECTION AND THE TRIPLE QUOTES SHOULD BE REMOVED '''

# This type of comment is fine and will run

def function():
...

Hope that helps. Reply if this doesn’t solve the problem.

It was error of resolving path in module, script was nornally started when i fix path. I just move my module to Python36-32\Lib\site-packages

Did you get to solve this by any chance? I am stuck with the same problem.
The script runs fine independently from python. Also I am able to invoke other python scripts as well from UI path.

I tried this, but no luck… were you able to get pass this?

Yes, I use Python scripts quite frequently now.

2 Important Points:

  1. Use a 32-Bit version of Python Interpreter
  2. Triple quote comments need to be removed.

Those are the only two issues I’ve dealt with. If you have more information on your error or if you could share your script, maybe I can help more.

1 Like

Hi Rautry,

I have the same problem. The sample Python script can run successfully, but my code doesnt work. My code is a data mining model, I try to import the first 2 line, but is also fail.
The first 2 line is following:
import pandas as pd
df = pd.read_excel(“C:/Users/mliu399/Desktop/IT_Report.xlsx”)
df.head()

could u help me solve the Error?

It’s hard to say without knowing where/how this is failing. Are you getting an error code?

I tried your code, but it doesn’t produce anything in Output from the df.head() method.

Instead, I put everything in a function and passed the result to a PythonObject in UiPath and then converted that to its corresponding object (in this case, an integer for testing). I used the following script:

import pandas as pd


def get_df_head():
    df = pd.read_excel('C:/Users/******/Documents/UiPath/sandbox/Data/IT_Result.xlsx')
    return df.get_values()[0][0]

I then print this value to Output. This worked for me, but I’m not sure if it solves your exact problem.

I think I find the reason. Do you wrap your own code in a class? My code is a model of data mining and is not packaged. This may be the reason why I can’t run. You use def xxxxxxxxx

I didn’t wrap anything in a class. The function is standalone in the script. What I posted was literally the entire script for my file ‘pythonTest.py’

I simply called the method from the script with “Invoke Python Method” in UiPath.

If you found the solution to your problem, could you share the what the solution was?

Sure, if i can run successfully, i will share the solution later.
LOVE U , bro.:kissing_heart:

Hi,

Here is the script that i am trying to invoke from UI path. it works independently without any issues, but getting an error ( Error resolving type specified in JSON ‘Python.Runtime.PythonException, Python.Runtime’. Path ‘$type’, line 1, position 462.) while trying to execute from UI Path. I have tried last couple of days trying to resolve , but no luck. Any help would be of great help.

from vaderSentiment import SentimentIntensityAnalyzer
analyser = SentimentIntensityAnalyzer()
def sentimentscores(sentence):
snt = analyser.polarity_scores(sentence)
print(“{:-<40} {}”.format(sentence, str(snt)))
scomp = analyser.polarity_scores(sentence)[‘compound’]
return scomp

First error I found is that you should be importing from vaderSentiment.vaderSentiment:

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

My second thought is that you probably don’t have vaderSentiment installed for your 32-Bit version of Python. You need to be careful with which interpreter is used in your IDE vs. what UiPath is using.

Once I installed vaderSentiment to my 32-Bit Python library folder, this script ran for me:

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer`
analyser = SentimentIntensityAnalyzer()`
def sentimentscores(sentence):`
    snt = analyser.polarity_scores(sentence)
    print("{:-<40}{}".format(sentence, str(snt)))
    scomp = analyser.polarity_scores(sentence)['compound']
    return scomp

I’m using the following sequence for this:

  • Python Scope
    • Load Python Script
    • Invoke Python Method (Remember input parameters)
    • Get Python Object
    • Write Line

I’ve attached my sequence XAML file for this, but you’ll have to use your own python script.

PythonTests.xaml (7.0 KB)