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

query() Not functioning #60

Closed masecla22 closed 5 years ago

masecla22 commented 6 years ago

I am trying to make a discord bot that pings minecraft servers. This is my code (which just so happens to be the example you provided) ` # If you know the host and port, you may skip this and use MinecraftServer("example.org", 1234) server = MinecraftServer("doge.bitquest.co",25565)

'status' is supported by all Minecraft servers that are version 1.7 or higher.

        status = server.status()
        print("The server has {0} players and replied in {1} ms".format(status.players.online, status.latency))
        # 'ping' is supported by all Minecraft servers that are version 1.7 or higher.
        # It is included in a 'status' call, but is exposed separate if you do not require the additional info.
        latency = server.ping()
        print("The server replied in {0} ms".format(latency))
        # 'query' has to be enabled in a servers' server.properties file.
        # It may give more information than a ping, such as a full player list or mod information.
        query = server.query()
        print("The server has the following players online: {0}".format(", ".join(query.players.names)))`

And when I run this i get the following error The server has 5 players and replied in 416.592 ms The server replied in 374.217 ms Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\super\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "C:\Users\super\Desktop\BOTPY\DogeBit\bot.py", line 104, in on_message query = server.query() File "C:\Users\super\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mcstatus\server.py", line 82, in query raise exception File "C:\Users\super\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mcstatus\server.py", line 77, in query querier.handshake() File "C:\Users\super\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mcstatus\querier.py", line 32, in handshake packet = self._read_packet() File "C:\Users\super\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mcstatus\querier.py", line 25, in _read_packet packet.receive(self.connection.read(self.connection.remaining())) File "C:\Users\super\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mcstatus\protocol\connection.py", line 175, in read result.extend(self.socket.recvfrom(self.remaining())[0]) socket.timeout: timed out The server is online, and has the query enabled in it's code.

MarkL4YG commented 6 years ago

Please put your code in a gist or at least proper code tags o_o!

masecla22 commented 6 years ago

Sorry >:

MarkL4YG commented 6 years ago

No worries please just do that so we can properly read the code/logs in order to help you ':D

masecla22 commented 6 years ago

https://gist.github.com/masecla22/ee3ae0b16da64a5ff76adbdaee1a982f This should do it

MarkL4YG commented 6 years ago

Please also remember to add the error exception/log to the gist for the next time.

For now socket.timeout: timed out verify your server to be reachable from the machine the script is running on.

netmonger commented 6 years ago

Double check that the server has enable-query=true in the server.properties. That was my problem. Once set to true I was getting results for a query.

kevinkjt2000 commented 5 years ago

@masecla22 Has this issue been resolved for you?

kevinkjt2000 commented 5 years ago

After going through several of the older issues, I'm fairly certain that what netmonger is saying is the likely issue.