Comments (4)
@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.
from mcstatus.
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)
from mcstatus.
@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.
from mcstatus.
@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.
from mcstatus.
Related Issues (20)
- MCSTATUS raw HOT 2
- Can't ping server on Termux HOT 5
- How do I run mcstatus? HOT 1
- status.version does not have a sensible string representation HOT 3
- Drop support for python 3.6
- Decode ISO 8859-1 into UTF-8
- minecrafBedrockServer failing to connect to a server HOT 5
- TypeError: an integer is required (got type NoneType) HOT 2
- Community Chat? HOT 2
- Key existence for COLOR_MAP is not being checked HOT 3
- Complex Description Styles are lacking test coverage HOT 3
- How to get server name / motd ?
- Update click to 8.0.0 HOT 2
- Raising errors on invalid ip requires rewrite of client logic HOT 15
- Support multiple types of formatting for MOTD
- Synchronous operations inside async functions HOT 1
- To replace sync 'dns.resolver.resolve' with `dns.asyncresolver` HOT 1
- UDPAsyncSocketConnection cannot write anything special itself HOT 3
- Unable to use module in a python script HOT 5
- Getting timeout for status.plays.online HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mcstatus.