服务器中 运行 应用程序时的 Py4j 异常

Py4j Exceptions when running application in a server

我使用 py4j 创建了一个应用程序,可以使用 java 应用程序将数据从 python 保存到 SQL 数据库,当我 运行 JVM 作为一个应用程序,它实际上保存数据。但是当我 运行 服务器中的代码时,它返回 exception.Therfore 我想也许我的服务器(Wildfly)和 Py4j 使用相同的端口所以我按照 turotial 的建议更改了默认的 py4j 端口并且这是python边修改后的样子:

from py4j.java_gateway import JavaGateway, GatewayParameters
gateway = JavaGateway(GatewayParameters(port=25335))
testBD = gateway.entry_point
DBin = gateway.jvm.com.packtpub.wflydevelopment.ch.Application(10,3) #calling constructor 
testBD.create(DBin)

但我仍然有一个例外:

    Traceback (most recent call last):
File "C:\Users\user\Desktop\test.py", line 4, in 
DBin = gateway.jvm.com.packtpub.wflydevelopment.ch.Application(10,3) 
File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\py4j-0.9-py3.5.egg\py4j\java_gateway.py", line 1185, in getattr
answer = self._gateway_client.send_command(
AttributeError: 'GatewayParameters' object has no attribute 'send_command'

如有任何建议,我们将不胜感激。

我从 https://github.com/bartdag/py4j/issues/180 的问题中得到了 bartdag 的回答,他指出将 GatewayParameter 实例指定为参数 "gateway_parameters" 是可行的。

# This produces the error 
gateway = JavaGateway(GatewayParameters(address='192.168.99.100', port=25333))

但添加参数名称使其有效:

# This solves it the error 
gateway = JavaGateway(gateway_parameters=GatewayParameters(address='192.168.99.100', port=25333))