[Python] Mcstatus keep returning a ConnectionrRefuseError every time when I try to ping a...

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I am a newbie to Minecraft servers and servers in general , and my friend want me to help him to make a discord bot for his server. Yesterday I came across this module call mcstatus in python and I decided to use it to fetch information from his Minecraft server to see if it is online or not , but whenever i try to connect to his mincraft server, it return with a ConnectionRefuseError: [WinError 10061] No connection could be made because the target machine actively refused , this is my code:

    async def online(ctx):
    try:
    server = MinecraftServer.lookup("95.217.72.187:56043")
    status = server.status()
    await ctx.send(status)
    except:
    await ctx.send("server is offline")


    and the error is

    Ignoring exception in command online:
    Traceback (most recent call last):
    File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
    File "C:/Users/USER/PycharmProjects/untitled5/tcpe bot.py", line 51, in online
    status = server.status()
    File "C:\Users\USER\AppData\Roaming\Python\Python38\site-packages\mcstatus\server.py", line 56, in status
    connection = TCPSocketConnection((self.host, self.port))
    File "C:\Users\USER\AppData\Roaming\Python\Python38\site-packages\mcstatus\protocol\connection.py", line 131, in __init__
    self.socket = socket.create_connection(addr, timeout=timeout)
    File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 808, in create_connection
    raise err
    File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 796, in create_connection
    sock.connect(sa)
    ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
    File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
    File "C:\Users\USER\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
    discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it


    anyone know why this is happening and pls help i tried mcipc but it show the same error why is this happening and is it because of my codes's problem or is my firewall and stuff

    Continue reading...

Compartilhe esta Página