0

I have created an application using py4j that makes it possible to save data from python in to SQL database using a java application,everything works so fine when i run the JVM as an application and it actually saves the data. But when i run the code in a server it gives me back an exception.Therfore i thought maybe my server(Wildfly) and Py4j are using the same port so i changed the default py4j port as the turotial suggested and this is how the python sides looks like after modification:

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)

but i m still having an exception:

    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'

Any suggestions would be very much appreciated.

raeX
  • 3,197
  • 2
  • 14
  • 21

1 Answers1

1

I got the answer from bartdag from the issue at https://github.com/bartdag/py4j/issues/180, he pointed out that specifying the GatewayParameter instance to the argument "gateway_parameters" it works.

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

But adding the argument name makes it work:

# This solves it the error 
gateway = JavaGateway(gateway_parameters=GatewayParameters(address='192.168.99.100', port=25333))
Codious-JR
  • 1,658
  • 3
  • 26
  • 48