Python Forum
Jython macro which uses PythonInterpreter and Redis script gives an error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jython macro which uses PythonInterpreter and Redis script gives an error
#1
Hi,

We are trying to use Jython with Redis script within confluence using a Jython macro.
We are able to execute the action using Jython from the command line and able to read the variable from redis database and get the result, but when we try to use the PythonInterpreter class from within Java application we get the below error. It would be great can suggest ,how to handle this error.

Quote:Traceback (most recent call last):
line 4, in
File “/opt/jython/Lib/site-packages/redis/ init .py”, line 1, in
from redis.client import Redis, StrictRedis
SyntaxError: (“no viable alternative at input ‘’’‘“, (‘/opt/jython/Lib/site-packages/redis/client.py’, 28, 13, ‘’))

Our execution piece of code for reference:

Quote: try {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.setOut(out);
interpreter.setErr(err);
interpreter.exec(code);
} catch (PyException exception) { // Exception from parsing script
errorText = getModifiedErrorText(exception.toString());
errorTitle = errorText.startsWith("SyntaxError") ? "Syntax error" : "Error running script";
} catch (Exception exception) { // Some other exception from the script
errorTitle = "Unexpected error running script";
errorText = exception.toString();
}

Please let us know if any thing is not clear or need more information to give a solution to this problem.
Reply
#2
More relavant piece of code:
Quote: try {
Properties properties = new Properties();
properties.setProperty("python.home", "../jython2.7.1/");
properties.setProperty("python.path", "../jython2.7.1/Lib");
properties.setProperty("python.import.site", "false");
PythonInterpreter.initialize(System.getProperties(), properties, new String[] {""});
PythonInterpreter python = new PythonInterpreter();
String script = "import sys\n" + "sys.path.append(\"../jython2.7.1/Lib\")\n" + "\n" + "import redis\n"
+ "r = redis.Redis(host='localhost', port=6379)\n" + "r.get('foo')";
python.set("script", new PyString(script));
python.exec(script);
python.close();
} catch (Exception e) {
e.printStackTrace();
}
Reply
#3
We are getting the following error for the above piece of sample. Even for "import redis" statemenet we are getting the error.
Quote:Traceback (most recent call last):
File "<string>", line 4, in <module>
ImportError: No module named redis
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question convert autohotkey script to python / macro - press key when pixel get colour willson94d 1 3,572 Jan-01-2022, 08:13 PM
Last Post: Yoriz
  Auto-populate Macro variables Spartan314 3 2,608 Mar-08-2021, 12:36 AM
Last Post: Spartan314
  How do I reduce the time to Invoke Macro via Python? JaneTan 1 2,074 Dec-28-2020, 06:46 AM
Last Post: buran
  Hi Guys, please help me to write SAS macro parameter equivalent code in Python Manohar9589 2 2,536 Jun-14-2020, 05:07 PM
Last Post: Larz60+
  Receive data from Redis RQ worker process freak14 0 1,865 Jul-15-2019, 12:39 PM
Last Post: freak14
  Com Error with macro within for loop due to creating new workbook in the loop Lastwizzle 0 1,337 May-18-2019, 09:29 PM
Last Post: Lastwizzle
  run an excel macro with python mmolet 1 8,951 Apr-02-2019, 09:36 AM
Last Post: Vinci141
  SAS Equivalent of Macro variable in Python AI_ML_Neophyte 4 11,522 Mar-29-2019, 08:14 AM
Last Post: FelixS
  Json dictionnary on Redis katsu707 1 2,409 Dec-04-2018, 11:59 AM
Last Post: DeaD_EyE
  Jython code throws ImportError when invoked from a Java jar dchucks 6 7,022 Aug-02-2018, 05:09 AM
Last Post: dchucks

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020