【问题标题】:Py4j Exceptions when running application in a server在服务器中运行应用程序时的 Py4j 异常
【发布时间】:2015-12-14 16:19:58
【问题描述】:

我使用 py4j 创建了一个应用程序,它可以使用 java 应用程序将 python 中的数据保存到 SQL 数据库中,当我将 JVM 作为应用程序运行并且它实际上保存了数据时,一切正常。但是当我在服务器上运行代码时,它给了我一个异常。Therfore我想也许我的服务器(Wildfly)和Py4j正在使用相同的端口,所以我按照教程的建议更改了默认的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'

非常感谢任何建议。

【问题讨论】:

    标签: java python py4j


    【解决方案1】:

    我从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))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-02
      • 2012-03-30
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多