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

server.query() Timed Out #177

Closed Gu-f closed 2 years ago

Gu-f commented 2 years ago

server.ping() and server.status() normal working but server.query() timed out.

Traceback (most recent call last):  
  File "test.py", line 8, in <module>  
    query = server.query()  
  File "/usr/local/lib/python3.6/site-packages/mcstatus/server.py", line 169, in query  
    raise exception_to_raise_after_giving_up  
  File "/usr/local/lib/python3.6/site-packages/mcstatus/server.py", line 164, in query  
    querier.handshake()  
  File "/usr/local/lib/python3.6/site-packages/mcstatus/querier.py", line 48, in handshake  
    packet = self._read_packet()  
  File "/usr/local/lib/python3.6/site-packages/mcstatus/querier.py", line 41, in _read_packet  
    packet.receive(self.connection.read(self.connection.remaining()))  
  File "/usr/local/lib/python3.6/site-packages/mcstatus/protocol/connection.py", line 240, in read  
    result.extend(self.socket.recvfrom(self.remaining())[0])  
socket.timeout: timed out

python3.6 os: centos 7

Iapetus-11 commented 2 years ago

Query can be enabled/disabled by servers. The server you're trying to use it on most likely has query disabled, hence why it times out.

Gu-f commented 2 years ago

Is it the enable-query in the server.properties file? I set enable-query to true, but it still timed out. Besides enable-query, it also has query.port, query. port and server-port are the same. They are both 25565. Is this normal?

Iapetus-11 commented 2 years ago

It is in the server.properties file, and it is normal for it to be on the same port. I don't know why it's not working then. What server software and version are you running?

Gu-f commented 2 years ago

This server is running Paper version git-Paper-399 (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT) (Git: d4318a6 on ver/1.17.1)
And
This server is running LoliServer version 1.16.5-a3891ce (MC: 1.16.5) (Implementing API version 1.16.5-R0.1-SNAPSHOT, Forge version 36.2.19)
Neither of them works.

Gu-f commented 2 years ago

Thanks a lot. After many attempts, I solved the problem. It is because the firewall does not allow UDP protocol communication. I only turn on TCP protocol......... server.query() works normally under the following conditions: firewall - (UDP -25565 and TCP -25565) -accept server.properties - (enable-query:=true and query.port=25565)

Thanks a lot.

kevinkjt2000 commented 2 years ago

Glad you figured it out! Apologies that the documentation still isn’t better yet for this.

This is pinned in issue #164 and mentioned in #136

wxydejoy commented 2 years ago

plaease list it in README, thanks

wxydejoy commented 2 years ago

@kevinkjt2000

ItsDrike commented 2 years ago

plaease list it in README, thanks

The need to enable query is mentioned.

https://github.com/Dinnerbone/mcstatus/blob/7fa3c2be25408309c7fc5f3704230deccea8bd6e/README.md?plain=1#L31

But with custom firewall configurations, it's up to the user to know when their firewall is blocking their traffic.

I suppose we could add a note of it, but that's like asking every program that makes connections anywhere, to add a notice like this. You should probably know that if you want to make connections to some non-standard ports and protocols which your firewall isn't allowing that you may need to enable it. Though I did see more issues like these where firewall was the cause, so it may be worth it, but it still feels a bit weird, I mean it's fairly obvious that to you need to allow your firewall to make the connection to get a response.

kevinkjt2000 commented 2 years ago

This is a closed issue. #136 is tracking the documentation overhaul that will include this.