Giter Club home page Giter Club logo

Comments (4)

kevinkjt2000 avatar kevinkjt2000 commented on August 14, 2024 2

@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 pinging the server.

from mcstatus.

MarkL4YG avatar MarkL4YG commented on August 14, 2024

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.

ubergeek77 avatar ubergeek77 commented on August 14, 2024

@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.

MarkL4YG avatar MarkL4YG commented on August 14, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.