pypresence
pypresence copied to clipboard
Unhandled Exception "struct.error" in presence.py
Exception in thread Thread-2:
Traceback (most recent call last):
File "Python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "Python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "utils\alt_funcs.py", line 727, in rpcLoop
RPC.update(details=getSentence(_vars.room), state=f'Current money: {_vars.var["player"]["money"]}', large_image='wood1024', large_text=f'Total playtime: {timeConvert()
File "Python38\site-packages\pypresence\presence.py", line 36, in update
return self.loop.run_until_complete(self.read_output())
File "Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "Python38\site-packages\pypresence\baseclient.py", line 82, in read_output
status_code, length = struct.unpack('<II', preamble[:8])
struct.error: unpack requires a buffer of 8 bytes
Sometimes this error raises, it happened various times already and it's normaly when Presence() frozens and you close Discord, this error will raise.
I believe it should be handled here: https://github.com/qwertyquerty/pypresence/blob/4fc19b14284d87e2e02ea57c74722ee9a4ff20e3/pypresence/baseclient.py#L80-L85
something along:
try:
preamble = await self.sock_reader.read(8)
status_code, length = struct.unpack('<II', preamble[:8])
data = await self.sock_reader.read(length)
except BrokenPipeError:
raise InvalidID
except struct.error:
raise PyPresenceException