Closed wiihoffmann closed 9 years ago
Can you paste your script here or on hastebin.com or something?
Right now i'm just trying to get the query feature to work so im using the code supplied on the main page of the repository. the code i'm using is below and in its entirety (i removed the ip as i shouldn't be giving it out):
from mcstatus import MinecraftServer
server = MinecraftServer("i purposely removed the ip") query = server.query() print("The server has the following players online: {0}".format(", ".join(query.players.names)))
Try this server: 54.69.165.139 -- it has the query proto enabled and has a dummy client connected.
It works for me using Python 2.7.6 and mcstatus 2.1 on Windows 7.
Thanks, it would appear that I set something up wrong in the server properties as the ip winny supplied works great. Thank you all for the help
By the way since 1.7 the regular server list ping (using the .status()
method) includes a limited list of players connected to the server. This should work on all servers without modifying servers.properties
to enable the Query proto.
Sorry but i'm rather new to python and as a result i can't get the .status() method of receiving a limited list of names names to work. Would it be possible for someone to leave an example of how to use this method?
Sure -- you may want to read the official python tutorial, however.
Run it like this:
$ python2 ping_example.py 54.69.165.139
A Minecraft Server (54.69.165.139) v1.8.3 210.007ms 2/20 dummy, blue_calx
#!/usr/bin/env python
from mcstatus.server import MinecraftServer
import sys
def print_status(address):
server = MinecraftServer(address)
status = server.status()
if status.players.sample:
players_string = ', '.join(p.name for p in status.players.sample)
else:
players_string = ''
print('{0} ({1}) v{2} {3}ms {4}/{5}{6}{7}'.format(
status.description,
address,
status.version.name,
status.latency,
status.players.online,
status.players.max,
bool(players_string)*' ', # Only include space if there is data.
players_string,
))
def main():
for arg in sys.argv[1:]:
print_status(arg)
if __name__ == '__main__':
main()
Really, bringing an old thread back to life by posting a useless comment?
I have the same problem using mcstatus 2.1 in a Django app. The problem also occurs when using mcstatus outside of the Django app. I also tested it with Python 2.7, on Windows, and Linux - no difference. It always just times out during the UDP handshake. Maybe related to #37? Any solution? The minecraft server is version 1.8.8 and I can query it just fine via https://dinnerbone.com/minecraft/tools/status/. Assuming this uses the same code, I don't quite understand the problem.
When I disable my firewall instead of the timeout I receive the following error at the same location:
Exception Value: [WinError 10054] An existing connection was forcibly closed by the remote host
Django Version: 1.8.4
Python Version: 3.5.0
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mclobby')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')
Traceback:
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Mathias\PycharmProjects\mclobby\mclobby\views.py" in query
27. query = server.query()
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\server.py" in query
82. raise exception
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\server.py" in query
77. querier.handshake()
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\querier.py" in handshake
32. packet = self._read_packet()
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\querier.py" in _read_packet
25. packet.receive(self.connection.read(self.connection.remaining()))
File "C:\Users\Mathias\AppData\Local\Programs\Python\Python35-32\lib\site-packages\mcstatus\protocol\connection.py" in read
172. result.extend(self.socket.recvfrom(self.remaining())[0])
Exception Type: timeout at /query
Exception Value: timed out
@Bunkerbewohner Please create your own issue instead of piggybacking off of someone else's. Locking this conversation.
i am trying to make a python program where i get an email whenever certain people join the server, however when i try to query the server i get this error:
Traceback (most recent call last): File "D:\Josh\Desktop\test1.py", line 5, in
query = server.query()
File "D:\Programs\python\lib\site-packages\mcstatus\server.py", line 82, in query
raise exception
File "D:\Programs\python\lib\site-packages\mcstatus\server.py", line 77, in query
querier.handshake()
File "D:\Programs\python\lib\site-packages\mcstatus\querier.py", line 32, in handshake
packet = self._read_packet()
File "D:\Programs\python\lib\site-packages\mcstatus\querier.py", line 25, in _read_packet
packet.receive(self.connection.read(self.connection.remaining()))
File "D:\Programs\python\lib\site-packages\mcstatus\protocol\connection.py", line 172, in read
result.extend(self.socket.recvfrom(self.remaining())[0])
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
additional info: query is enabled in the server.properties running vanilla minecraft when using this site http://goo.gl/YRVYIQ i can see who is on the server just fine i get the error on both my raspberry pi and pc