pyCraft
pyCraft copied to clipboard
Disconnect causing EOF errors
This is the code I am using to reconnect/connect to the server
async def reco(self): try: self.connection.disconnect() await asyncio.sleep(60) except: pass self.connection.connect() await asyncio.sleep(3) packet = serverbound.play.ChatPacket() packet.message = '/server witch' self.connection.write_packet(packet) print('Logged In')
This is the error I get when I execute that code (only happens at the self.connection.disconnect() line from what I can see i.e. when reconnecting)
Exception in thread Networking Thread: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 462, in run self._run() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 496, in _run self.connection.file_object, timeout=read_timeout) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 535, in read_packet length = VarInt.read(stream) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/types/basic.py", line 113, in read raise EOFError("Unexpected end of message.") EOFError: Unexpected end of message.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 466, in run self.connection.handle_exception(e, sys.exc_info()) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 412, in handle_exception raise(*exc_info) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/future/utils/init.py", line 415, in raise raise exc.with_traceback(tb) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 462, in run self._run() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 496, in _run self.connection.file_object, timeout=read_timeout) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/connection.py", line 535, in read_packet length = VarInt.read(stream) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/minecraft/networking/types/basic.py", line 113, in read raise EOFError("Unexpected end of message.") EOFError: Unexpected end of message.
Sorry for the garbage formatting I don't know how GitHub works with codeblocks, tilda doesnt seem to respect my tabs/enters
No matter how or where I use self.connection.disconnect(immediate=True) i always get EOF errors
Take a look at the handle_exception argument to Connection here: https://pycraft.readthedocs.io/en/latest/connecting.html#minecraft.networking.connection.Connection
Example of usage: https://github.com/joodicator/mcchat2/blob/master/mcchat2.py#L714-L719