handle socket.error

This commit is contained in:
Luke Rogers 2014-03-01 13:12:48 +13:00
parent f05a35dd96
commit fd7253ded7

View file

@ -61,6 +61,7 @@ pack_port = lambda i: struct.pack('>H', i)
def mcping_modern(host, port):
""" pings a server using the modern (1.7+) protocol and returns data """
try:
# connect to the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@ -89,6 +90,8 @@ def mcping_modern(host, port):
# Close our socket
s.close()
except socket.error:
raise PingError("Socket Error")
# Load json and return
data = json.loads(d.decode('utf8'))