Dinnerbone / mcstatus

A Python class for checking the status of an enabled Minecraft server
http://dinnerbone.com/minecraft/tools/status/
1.11k stars 146 forks source link

Bungee secured with TCPShield returning error: TIMED OUT #156

Closed nothendev closed 3 years ago

nothendev commented 3 years ago

Code with getting response from server Screenshot_54 Code making embed with data from returned array by get_ping_offline() Screenshot_55

And error: ` someone queued to check magma online Ignoring exception in command server: Traceback (most recent call last): File "I:\coding\py\env\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "I:\coding\py\magmabot\modules\fun.py", line 54, in online_cmd embed.add_field(name='Пинг:', value='{0}'.format(bot_utils.get_ping_offline()[0]), inline=False) File "I:\coding\py\magmabot\bot_utils.py", line 77, in get_ping_offline qu = srv.query() File "I:\coding\py\env\lib\site-packages\mcstatus\server.py", line 170, in query raise exception_to_raise_after_giving_up File "I:\coding\py\env\lib\site-packages\mcstatus\server.py", line 165, in query querier.handshake() File "I:\coding\py\env\lib\site-packages\mcstatus\querier.py", line 48, in handshake packet = self._read_packet() File "I:\coding\py\env\lib\site-packages\mcstatus\querier.py", line 41, in _read_packet packet.receive(self.connection.read(self.connection.remaining())) File "I:\coding\py\env\lib\site-packages\mcstatus\protocol\connection.py", line 240, in read result.extend(self.socket.recvfrom(self.remaining())[0]) ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

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

Traceback (most recent call last): File "I:\coding\py\env\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "I:\coding\py\env\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "I:\coding\py\env\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: ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host ` Using discord.py 1.7.3, mcstatus 6.5.0 (last release) and python 3.9

Iapetus-11 commented 3 years ago

You should be using the lookup() function to perform that DNS SRV record lookup, that may fix it. It also could be the case that server just has query disabled.

Also, you're using regular old blocking code in an async environment, that is bad because while that blocking/sync code is running, the rest of your bot will freeze. Look into the async methods of mcstatus for your purpose or use a ThreadPoolExecutor. Mcstatus does not provide an async lookup() method so I created one in one of my old projects here.

kevinkjt2000 commented 3 years ago

Query must be enabled in server.properties and configured to use any available UDP port (by default this is the same port number that the TCP game is running on). That could be the issue here if you are using a firewall that supports TCP only.

kevinkjt2000 commented 3 years ago

For the data you are getting, TCP status should be enough:

from mcstatus import MinecraftServer

mc = MinecraftServer("mc.magma-cube.ru")
status = mc.status()
print(f"players: {status.players.online} / {status.players.max}")
kevinkjt2000 commented 3 years ago

Is this resolved now?