isaackogan / TikTokLive

Python library to receive live stream events (comments, gifts, etc.) in realtime from TikTok LIVE.
https://isaackogan.github.io/TikTokLive/
MIT License
786 stars 164 forks source link

Automatic off event data capture but user still live #216

Open masumr opened 2 months ago

masumr commented 2 months ago

It seems like the user is live, and the package is supposed to provide event data. However, after some time, the event data capture stops, and an error is generated below- image

Package Version

My version of TikTokLive is 6.0.5.

isaackogan commented 2 months ago

Thanks for the report, though I can't see where the error was originating from.

Do you have a larger stacktrace?

Please also double check the version with pip freeze.

masumr commented 2 months ago

Rechecking with TikTokLive package version 6.0.5 image

isaackogan commented 2 months ago

Hi, is that pip freeze or requirements.txt? They are not necessarily equivalent. It's likely your issue is genuinely occurring in the latest version but I'd just like to confirm since I can't reproduce it myself.

Best, Isaac

masumr commented 2 months ago

Let me, describe things more clear. Back in the version 6.0.3 and 6.0.4 I didn't got this type of issue. But , now in this latest version 6.0.5 , for every tiktok live, I am getting this type of issues. User is in live (say for example 2-3 hrs+) suddenly , the event-data stopped coming BUT USER STILL IN LIVE at tiktok.

Please, let me know, if there's any point of confusion.

diego-fmachado commented 2 months ago

I get a similar error sometimes when using client.disconnect():

Exception in thread [ConnectionManager]Async-stop:
Traceback (most recent call last):
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 963, in transfer_data
    message = await self.read_message()
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 1033, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 1108, in read_data_frame
    frame = await self.read_frame(max_size)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 1165, in read_frame
    frame = await Frame.read(
            ^^^^^^^^^^^^^^^^^
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\framing.py", line 68, in read
    data = await reader(2)
           ^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\asyncio\streams.py", line 726, in readexactly
    raise exceptions.IncompleteReadError(incomplete, n)
asyncio.exceptions.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Program Files\Python311\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\...\code_ultimate\module\base\module.py", line 219, in wait
    future.result()
  File "C:\Program Files\Python311\Lib\concurrent\futures\_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "C:\Users\...\code_ultimate\module\connection_manager\client\client_new.py", line 30, in stop
    await self._client.disconnect()
  File "C:\Users\...\venvnew\Lib\site-packages\TikTokLive\client\client.py", line 212, in disconnect
    await self._event_loop_task
  File "C:\Users\...\venvnew\Lib\site-packages\TikTokLive\client\client.py", line 233, in _client_loop
    async for event in self._ws_loop(initial_response):
  File "C:\Users\...\venvnew\Lib\site-packages\TikTokLive\client\client.py", line 257, in _ws_loop
    async for response_message in self._ws.connect(*self._build_connect_info(initial_response)):
  File "C:\Users\...\venvnew\Lib\site-packages\TikTokLive\client\ws\ws_client.py", line 158, in connect
    async for webcast_message in self.connect_loop(uri, headers):
  File "C:\Users\...\venvnew\Lib\site-packages\TikTokLive\client\ws\ws_client.py", line 194, in connect_loop
    async for message in websocket:
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 498, in __aiter__
    yield await self.recv()
          ^^^^^^^^^^^^^^^^^
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 568, in recv
    await self.ensure_open()
  File "C:\Users\...\venvnew\Lib\site-packages\websockets\legacy\protocol.py", line 939, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent
isaackogan commented 2 months ago

Hey,

I get what you guys are saying but there isn't really a lot for me to do with it. There's no description of the code triggering the issue, and the stacktraces are not really helpful.

I'm not ashamed to say I could use a little help debugging here. Any ideas, thoughts?

diego-fmachado commented 1 month ago

I've solved this by supressing the exception in connect_loop, allowing the loop to open a new websocket connection