org.python.core.PyException: ImportError: cannot import name BytesIO at org.python.core.Py.ImportError(Py.java:329) ~[robotframework-4.1.2.jar:4.1.2] Error while executing robot file through maven

I am working with a spring boot project-
If I am executing the robot test file from web context it is throwing error-

@RestController
public class newcontroller {

@GetMapping("/test")
public String test(){

    String userHome = System.getProperty("user.home");
    Path path = Paths.get(userHome, "Downloads", "auth.robot");

    // Get the Downloads directory
    File dir = new File(userHome, "Downloads");

    System.out.println(path.toString());
    System.out.println(dir.toString());

    // Set Robot Framework arguments
    String[] robotArgs = {"-d", dir.toString(), path.toString()};
    System.out.println(Arrays.toString(robotArgs));
    int rc = RobotFramework.run(robotArgs);

    // Output the return code
    System.out.println("Return code: " + rc);
    return "success";

}

}

Error-

ERROR 13244 — [netpulse-tee-service] [nio-8091-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed: Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\tanish.kumar.m2\repository\org\robotframework\robotframework\4.1.2\robotframework-4.1.2.jar\Lib\robot_init_$py.class”, line 44, in

ImportError: cannot import name BytesIO
] with root cause

org.python.core.PyException: ImportError: cannot import name BytesIO
at org.python.core.Py.ImportError(Py.java:329) ~[robotframework-4.1.2.jar:4.1.2]

But If I am executing the robot test file using main() method it is working fine-

public class Helper {

public static void main(String[] args) {

    String userHome = System.getProperty("user.home");
    Path path = Paths.get(userHome, "Downloads", "auth.robot");

    // Get the Downloads directory
    File dir = new File(userHome, "Downloads");

    String[] robotArgs = {"-d", dir.toString(), path.toString()};
    int rc = RobotFramework.run(robotArgs);

    // Output the return code
    System.out.println("Return code: " + rc);

}

}

My pom.xml contains-

               <dependency>
			<groupId>org.robotframework</groupId>
			<artifactId>robotframework</artifactId>
			<version>4.1.2</version>
		</dependency>

		<dependency>
			<groupId>org.robotframework</groupId>
			<artifactId>robotframework-maven-plugin</artifactId>
			<version>2.1.0</version>
			<type>maven-plugin</type>
		</dependency>

		<dependency>
			<groupId>org.python</groupId>
			<artifactId>jython-standalone</artifactId>
			<version>2.7.3</version>
		</dependency>

Any help and suggestion is much appreciated.

Hi Tanish,

The good news is your running the last version of Robot Framework that was supported in Jython (4.1.2)

The bad news is Robot Framework 4.1.2 was released in 2021 and has not been supported for a few years now, with no plans for a future version of Robot Framework to be supported in Jython (until Jython releases a version that’s compatible with the python 3.x branch)

I notice your running jython 2.7.3, which was released in Sept 2022, so that might not be compatible with Robot Framework 4.1.2? I don’t know, but first thing I’d try is rolling back your jython version to 2.7.2, which was released in 2020, i.e. before Robot Framework 4.1.2.

Not sure what else to suggest?

Dave.