ammaraskar / pyCraft

Minecraft-client networking library in Python
Other
815 stars 183 forks source link

threading error #208

Open ViperLands opened 3 years ago

ViperLands commented 3 years ago
Networking Thread:
Traceback (most recent call last):
  File "C:\Users\daoud\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\daoud\Desktop\pyCraft-master\minecraft\networking\connection.py", line 589, in run
    self.connection._handle_exception(e, sys.exc_info())
  File "C:\Users\daoud\Desktop\pyCraft-master\minecraft\networking\connection.py", line 532, in _handle_exception
    raise exc_value.with_traceback(exc_tb)
  File "C:\Users\daoud\Desktop\pyCraft-master\minecraft\networking\connection.py", line 585, in run
    self._run()
  File "C:\Users\daoud\Desktop\pyCraft-master\minecraft\networking\connection.py", line 618, in _run
    packet = self.connection.reactor.read_packet(
  File "C:\Users\daoud\Desktop\pyCraft-master\minecraft\networking\connection.py", line 659, in read_packet
    length = VarInt.read(stream)
  File "C:\Users\daoud\Desktop\pyCraft-master\minecraft\networking\types\basic.py", line 154, in read
    byte = file_object.read(1)
  File "C:\Users\daoud\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 663, in readinto
    self._checkClosed()
ValueError: I/O operation on closed file.

whilst i try to authentificate and join a server.

from minecraft import authentication
from minecraft.exceptions import LoginDisconnect
from minecraft.networking.connection import Connection
from minecraft.networking.packets import Packet, clientbound, serverbound

raw = input("Enter your mc database format auth: ")
raw = raw.split(":")
auth_token = authentication.AuthenticationToken()
auth_token.authenticate(raw[0], raw[1])

connection = Connection(address="play.hypixel.net", port=25565, auth_token=auth_token, username=None)

@connection.listener(clientbound.login.DisconnectPacket, early=True)
def on_login_disconnect_packet(packet):
    print('Banned: %r' % packet.json_data)

@connection.exception_handler(LoginDisconnect)
def on_login_disconnect_exception(exc, exc_info):
    pass

try:
    connection.connect()
    print("logins seems to work fine")
    connection.disconnect()
    input("press any keys to proceed")
except LoginDisconnect as e:
    print("Caught error -- Login failed due: {0}".format(e.message)) # or str(e)

Edit: changed inline code to code blocks to make it readable - @joodicator

joodicator commented 3 years ago

@ViperLands Does the stack trace you posted above occur before or after the logins seems to work fine and press any keys to proceed messages? Do you know if the server is doing anything unusual, like rejecting the connection during login due to a ban?

By the way, I should note that the code

 connection.connect()
 print("logins seems to work fine")
 connection.disconnect()

will not do what the print message suggests, because connect returns as soon as the connection has been opened, which means this code would usually disconnect before any login attempt can be made (although this does depend on the timing, since that happens in another thread). However, this would not explain the above error, which shouldn't be happening.