无法在python rexpro连接

时间:2017-09-05 14:40:41

标签: python

我正在尝试在rexpro连接中创建一个全局变量,我可以在后续的执行调用中使用它,但全局变量不起作用。以下是一个简单的代码段。

from rexpro import RexProConnection
conn = RexProConnection('localhost', 8184, 'graph')
#number will become a global variable for this session
conn.execute("number = 5")
conn.execute("number")

当我在最后一行再次调用数字变量时出现以下错误

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    conn.execute("number")
  File "/opt/savvi-deps/python27/lib/python2.7/site-packages/rexpro/connectors/base.py", line 426, in execute
    response.raise_exception()
  File "/opt/savvi-deps/python27/lib/python2.7/site-packages/rexpro/messages.py", line 198, in raise_exception
    raise exceptions.RexProScriptException(self.message)
rexpro.exceptions.RexProScriptException: An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: java.util.concurrent.ExecutionException: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: number for class: Script17

我想要的是一个管理对象,我可以在我的代码中使用后者,如下所示。

from rexpro import RexProConnection
conn = RexProConnection('localhost', 8184, 'graph')
#number will become a global variable for this session
conn.execute("mgmt=g.getManagementSystem()")
conn.execute("mgmt.makePropertyKey('name').dataType(String.class).make()")

此页面中的示例:http://rexpro-python.readthedocs.io/en/latest/quickstart.html

1 个答案:

答案 0 :(得分:0)

最后破解了它。默认情况下,isolate选项似乎为true,它封装了要在下一行中使用的变量。以下代码有效。

from rexpro import RexProConnection
conn = RexProConnection('localhost', 8184, 'graph')
#number will become a global variable for this session
conn.execute("number = 5",isolate=False)
conn.execute("number")