Run a Python Script that contain a dictionary

I have a python script that contains a dictionary and when I try and load the script into Studio the Python Object returns - PythonObject { Id=[00000000-0000-0000-0000-000000000000] }

The xaml is using UiPath.python.activites
The xaml steps are Load Python → Invoke Python → Get Python
When comment out payload = {“iat”: now} the Load Step with be successful and Get will return “Hello”

Using Python 3.10.

Script def time(sa_keyfile):
import time
import argparse
import google
import google.auth.crypt
import google.auth.jwt
import requests

now = int(time.time())

# build payload
    payload = {"iat": now}

return "Hello"

Hi @Kyle_Grimm,

Welcome to the community!

Just convert the output to string in python and return it.

Incase anyone find this in the future.

From what I can tell you cannot create a dictionary in the python code.

Based on this thread - Invoke python method

The work around I found was to create the dictionary and it values in Studio then convert that dictionary to a json string.

In the python code add
import json

To convert the json back to a dictionary in the python script
jsonTodict = json.loads(jsonPayload)

To change any of the value datatype in the dictionary
jsonTodict[‘iat’] = int(jsonTodict[‘iat’])

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.