Error: Parsing of json failed for [PythonActionEngineOutput]

I am in 7.9.0, I am trying to execute a python code and I get this error Error: Parsing of json failed for [PythonActionEngineOutput]
The documentation of PythonActionEngineOutput mentions that Action output is returned as a json containing the stdout log statements from the Python process and the result of the C3 action call but it is not clear to me how to avoid this error.
Thanks !

Are you using print in your Python code?

If you need to log things from Python, be sure to use the logger instead of print, since as the documentation says, we rely on stdout to communicate the result of the C3 action back to the caller. (I’m not too familiar with Python, but a quick web search suggests that Python’s print uses stdout by default?)

Here are some helpful posts regarding logging in Python:

Thanks Matt for your answer.

No, I am not using print but I am training a model and it outputs some logs so it might be the reason why the parsing fails. I am going to try catching these.

Hello @matt,

It looks like the stdout was the problem in my case. I found a workaround on https://github.com/facebook/prophet/issues/223 to suppress all print, even if the print originates in a compiled C/Fortran sub-function. It is now working.

class suppress_stdout(object):
    '''
    A context manager for doing a "deep suppression" of stdout in
    Python, i.e. will suppress all print, even if the print originates in a
    compiled C/Fortran sub-function.
       This will not suppress raised exceptions, since exceptions are printed
    to stderr just before a script exits, and after the context manager has
    exited (at least, I think that is why it lets exceptions through).
    '''
    def __init__(self):
        # Open a pair of null files
        self.null_fds = [os.open(os.devnull, os.O_RDWR) for _ in range(1)]
        # Save the actual stdout (1) and stderr (2) file descriptors.
        self.save_fds = [os.dup(1)]

    def __enter__(self):
        # Assign the null pointers to stdout and stderr.
        os.dup2(self.null_fds[0], 1)

    def __exit__(self, *_):
        # Re-assign the real stdout/stderr back to (1) and (2)
        os.dup2(self.save_fds[0], 1)
        # Close the null files
        for fd in self.null_fds + self.save_fds:
            os.close(fd)

#Example:
with suppress_stdout():
    model.fit(df=training_df)