1

I use mcpi: https://github.com/AdventuresInMinecraft/AdventuresInMinecraft-Linux Starting the local server. After, run program:

import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()
mc.postToChat("Hello Minecraft World")

I am facing the below error:

Traceback (most recent call last): 
File "/home/home/AdventuresInMinecraft/MyAdventures/HelloMinecraftWorld.py", line 2, in mc = minecraft.Minecraft.create() 
File "/home/home/.local/lib/python3.6/site-packages/mcpi/minecraft.py", line 376, in create return Minecraft(Connection(address, port)) 
File "/home/home/.local/lib/python3.6/site-packages/mcpi/connection.py", line 17, in init self.socket.connect((address, port))
ConnectionRefusedError: [Errno 111] Connection refused
Shiva
  • 2,627
  • 21
  • 33
trisestri
  • 11
  • 1
  • 2

2 Answers2

2

A ConnectionRefusedError means that the address + port combination was unable to be secured for this particular Minecraft server and thus raised an exception. This could be because some other application is already using the port of interest, the port is unavailable because of the OS, or a handful of other networking configuration mishaps.

But perhaps a better series of questions to ask yourself is:

  • What is the default address and port that minecraft.Minecraft.create() will attempt to launch / listen at?
  • Do I have access to that server (address + port)?
  • If I do have access, are there any security issues (AKA Firewall)?

This post has already addressed the root issue of your question, and I hope it gives you a good start at understanding the foundation of your problem.

Notice how their question mentions s.connect((host,port)) and your stack trace has self.socket.connect((address, port)) Looks like the same thing to me!

Some more reading: - localhost - check if port is in use

David Owens
  • 645
  • 6
  • 25
2

I encountered the same issue. I looked into the code of mcpi and found that the default port is 4711. However, a Minecraft Server's default port is 25565. All you need to do is add 2 parameters on the create() function. Code(Python):

mc = minecraft.Minecraft.create(address="127.0.0.1", port=25565)

btw change "address" in the code to the host of the server (only if you modified the "server.properties" file).

Also, ConnectionRefusedError doesn't mean that it's not secured, I believe it means that either the server is not online, it doesn't exist, or the server refused it for some reason.

EDIT: Oops sorry I just found out that mcpi actually connects to the RaspberryJam plugin which is hosted on another IP and port. The plugin runs on port 4711. So mcpi has the right port. So check if you have the RaspberryJam plugin installed. If not, download it from

https://www.spigotmc.org/resources/raspberryjuice.22724/

And put the .jar file inside the plugins folder in your server directory.

LolaKid
  • 51
  • 2