Search code examples
pythonpython-3.xminecraftsource-engine

python-valve rcon minecraft 'ConnectionRefusedError: [Errno 111] Connection refused'


I am trying to connect to RCON on a minecraft server hosted on my own network using python-valve. My code is as follows(Keep in mind it is only accessible on my network, hence my connection to localhost):

import valve.rcon
def rconsendCMD():
    address = ("127.0.0.1", 25575)
    valve.rcon.execute(address,"jeff","time set night")

That code, according to the documentation, should work fine yet it returns:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/client.py", line 307, in _run_event
    yield from getattr(self, event)(*args, **kwargs)
  File "bot.py", line 90, in on_message
    rconsendCMD()
  File "bot.py", line 43, in rconsendCMD
    valve.rcon.execute(address,"jeff","time set night")
  File "/usr/local/lib/python3.6/site-packages/valve/rcon.py", line 630, in execute
    with RCON(address, password) as rcon:
  File "/usr/local/lib/python3.6/site-packages/valve/rcon.py", line 325, in __enter__
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/valve/rcon.py", line 464, in wrapper
    return function(instance, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/valve/rcon.py", line 464, in wrapper
    return function(instance, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/valve/rcon.py", line 483, in connect
    self._socket.connect(self._address)
ConnectionRefusedError: [Errno 111] Connection refused

The documentation for 'valve.rcon.execute()' can be found here


Solution

  • I found out the problem. I am hosting the server on a seperate machine from what I'm executing the python code on. I tried to send it to connect to localhost rather than my private address within my network. Answer found here