Closed Mepth closed 5 years ago
I don't want to sound rude but that literally written on the first page here ^^''
https://github.com/Dinnerbone/mcstatus GitHub shows the ReadMe below the repo structure. Read "Usage".
(And remember to close the issue when you found what you were looking for)
@MarkL4YG Actually, it really isn't. Not only is the readme missing any mention of explicitly checking if a server is online, mcstatus will fail and terminate if a server is unreachable. This occurs under both Python2.7 and Python3.5, using all 3 possible options (ping, query, status).
Is there something I missed from the readme? If so, please feel free to point it out for me.
What I'm sure @maxim19116 is looking for is a graceful way to check if a server is online or not. I was looking for something like this myself, which is how I found this repository. While you might be able to do a try-except on the line of code that would cause the error, I don't find that a particularly good solution. Plus, any solution would have to make its way to this repository.
I want to integrate this into a php script that will run this command locally and return the status, and I'd rather not have to work my way around any possible fatal errors. That can get messy very quickly. Ideally, this script should return with something like "Couldn't contact the server!" to indicate that the server is either offline, or unreachable, with the former being assumed in the case of the latter.
@ubergeek77 If you want to submit code changes that would allow gracefully checking for the target machine to even respond feel free to open a PR. Although @Dinnerbone seems to be inactive on GH and afaik there's no Collaborator set on this repo.
@ubergeek77 socket.gaierror is raised when the DNS name cannot be resolved:
MinecraftServer("this.definitely.does.not.exist", 32768).status()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mcstatus/server.py", line 49, in status
connection = TCPSocketConnection((self.host, self.port))
File "mcstatus/protocol/connection.py", line 129, in __init__
self.socket = socket.create_connection(addr, timeout=timeout)
File "/usr/lib64/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
and socket.error with error coded 111 is raised when the connection is refused:
MinecraftServer("127.0.0.1", 25565).status()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mcstatus/server.py", line 49, in status
connection = TCPSocketConnection((self.host, self.port))
File "mcstatus/protocol/connection.py", line 129, in __init__
self.socket = socket.create_connection(addr, timeout=timeout)
File "/usr/lib64/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 111] Connection refused
and socket.timeout is raised when it cannot reach the target machine:
MinecraftServer("10.0.0.0", 25565).status()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mcstatus/server.py", line 49, in status
connection = TCPSocketConnection((self.host, self.port))
File "mcstatus/protocol/connection.py", line 129, in __init__
self.socket = socket.create_connection(addr, timeout=timeout)
File "/usr/lib64/python2.7/socket.py", line 575, in create_connection
raise err
socket.timeout: timed out
If none of these are sufficient enough for you, then I suggest going old school by ping
ing the server.
How can I check if the server is online?