Python Invoker program exception: ValueError : unknown file extension:

Hello

I have this strange error i cant figure out. this is my flow:

i am downloading file from gmail and using it then for processing i am accessing it in temp folder but i found out that it uses sort of double extension and i was thinking this is the problem:

here i am renaming it (and then as can be seen in previous activity i am moving that file so that it will be just with normal jpg

now i am loading this into python script for further processing:


so i am using the correct value for the file to be accessed with correct extension.

but i am still getting this error:

RemoteException wrapping System.AggregateException: One or more errors occurred. (Error invoking Python method) —> RemoteException wrapping System.InvalidOperationException: Error invoking Python method —> RemoteException wrapping System.InvalidOperationException: Python instantiation exception
Python Invoker program exception:
ValueError : unknown file extension:
at UiPath.Shared.Service.PythonResponse.ThrowExceptionIfNeeded()
at UiPath.Python.Service.PythonProxy.InvokeMethod(Guid instance,
String method,
IEnumerable1 args) at UiPath.Python.Impl.OutOfProcessEngine.<>c__DisplayClass15_0.<InvokeMethod>b__0() at System.Threading.Tasks.Task1.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)

this is the snippet i am using and it works on cmd actually run on exact same file i am having there in temp:

import pytesseract
from PIL import Image
import os

# Set the tesseract executable path
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"


def rotate_and_correct_image(In_FilePath):
    In_OutputPath = ""
    original_image = Image.open(In_FilePath)
    osd = pytesseract.image_to_osd(original_image)
    rotation_angle = int([line.split(":")[1].strip() for line in osd.split("\n") if "Rotate" in line][0])
    corrected_image = original_image.rotate(-rotation_angle, expand=True)
    corrected_image.save(In_OutputPath)
    return In_OutputPath  # Return the output file path

Any help would be very appreciated.

Based on Activities - Invoking a Python Script

I tested succesfully your script internally and I was able to rotate the image.

Prerequisites:

Tesseract installer for Windows from Home · UB-Mannheim/tesseract Wiki · GitHub

Python script

import sys
import os

try:
    sys.path.append(os.path.dirname(os.path.realpath(__file__)))
    import pytesseract
    from PIL import Image
except Exception as e:
    #print(f"Error during imports: {e}")
    raise

# Set the tesseract executable path
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

def rotate_and_correct_image(In_FilePath):
    try:
        In_OutputPath = In_FilePath
        original_image = Image.open(In_FilePath)
        osd = pytesseract.image_to_osd(original_image)
        #print("OSD Data:", osd)  # Debug print
        rotation_angle = int([line.split(":")[1].strip() for line in osd.split("\n") if "Rotate" in line][0])
        #print("Rotation Angle:", rotation_angle)  # Debug print
        corrected_image = original_image.rotate(-rotation_angle, expand=True)
        corrected_image.save(In_OutputPath)
        return In_OutputPath  # Return the output file path
    except Exception as e:
        return f"Error during image processing: {e}"

Use a rotated image for testing.
UiPath Studio 2025.0.157
UiPath.Python.Activities.1.8.2
UiPath.System.Activities.24.10.7
Python 3.12.8 64-bit

Python Scope

Library path: "C:\Program Files\Python312\python312.dll"
Path: "C:\Program Files\Python312"
Target: x64

Load Python Script

File: "C:\Users\marian.platonov\Desktop\Customer Issues\python_sample\rotateImage.py"
Result: out_LoadPythonScript

Invoke Python Method

InputParameters: new Object() {"C:\Users\marian.platonov\Desktop\Customer Issues\python_sample\Image to analyze.png"}
Instance: out_LoadPythonScript
Name: "rotate_and_correct_image"
Result: out_Python_Object

Get Python Object

PythonObject: out_Python_Object
Type: Object
Result: out_GetPythonObject

Log Message

Message: out_GetPythonObject.ToString

Example results:

For Success it will return the file name provided at Invoke Python Method activity

For Fail based on various errors which may occur in your Python script and file paths

I attached the project sample as a guidance:

RotateImageInPython.zip (534.0 KB)

Many thanks works now! i think that helped!