isaackogan / TikTokLive

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

TypeError: string indices must be integers #240

Closed aCS6 closed 2 months ago

aCS6 commented 2 months ago

While running the package, I faced the below error all the time.

2024-07-09 15:42:42,195 - httpx - INFO - HTTP Request: GET https://www.tiktok.com/@theoriginote/live "HTTP/1.1 200 OK"
2024-07-09 15:42:42,505 - httpx - INFO - HTTP Request: GET https://webcast.tiktok.com/webcast/room/check_alive/?aid=1988&app_language=en-US&app_name=tiktok_web&browser_language=en&browser_name=Mozilla&browser_online=true&browser_platform=Win32&browser_version=5.0%20%28Windows%20NT%2010.0%3B%20Win64%3B%20x64%29%20AppleWebKit%2F537.36%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F102.0.5005.63%20Safari%2F537.36&cookie_enabled=true&cursor=&internal_ext=&device_platform=web&focus_state=true&from_page=user&history_len=4&is_fullscreen=false&is_page_visible=true&did_rule=3&fetch_rule=1&last_rtt=0&live_id=12&resp_content_type=protobuf&screen_height=1152&screen_width=2048&tz_name=Europe%2FBerlin&referer=https%3A%2F%2Fwww.tiktok.com%2F&root_referer=https%3A%2F%2Fwww.tiktok.com%2F&msToken=&version_code=180800&webcast_sdk_version=1.3.0&update_version_code=1.3.0&uuc=1&device_id=50726871387963610829&room_id=%22roomId%22%3A%227389544423330564869%22&room_ids=%22roomId%22%3A%227389544423330564869%22 "HTTP/1.1 200 OK"
Traceback (most recent call last):
  File "/home/nahid/test/tiktok-events/one/test.py", line 47, in <module>
    client.run()
  File "/home/nahid/test/tiktok-events/one/tik-venv/lib/python3.10/site-packages/TikTokLive/client/client.py", line 200, in run
    return self._asyncio_loop.run_until_complete(self.connect(**kwargs))
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/nahid/test/tiktok-events/one/tik-venv/lib/python3.10/site-packages/TikTokLive/client/client.py", line 176, in connect
    task: Task = await self.start(**kwargs)
  File "/home/nahid/test/tiktok-events/one/tik-venv/lib/python3.10/site-packages/TikTokLive/client/client.py", line 127, in start
    if fetch_live_check and not await self._web.fetch_is_live(room_id=self._room_id):
  File "/home/nahid/test/tiktok-events/one/tik-venv/lib/python3.10/site-packages/TikTokLive/client/web/routes/fetch_is_live.py", line 47, in __call__
    return (await self.fetch_is_live_room_ids(room_id))[0]
  File "/home/nahid/test/tiktok-events/one/tik-venv/lib/python3.10/site-packages/TikTokLive/client/web/routes/fetch_is_live.py", line 66, in fetch_is_live_room_ids
    return [i["alive"] for i in response_json["data"]]
  File "/home/nahid/test/tiktok-events/one/tik-venv/lib/python3.10/site-packages/TikTokLive/client/web/routes/fetch_is_live.py", line 66, in <listcomp>
    return [i["alive"] for i in response_json["data"]]
TypeError: string indices must be integers

Package Version

My version of TikTokLive is 6.0.6.

antimagetiny commented 2 months ago

The same

zufarrizal commented 2 months ago

I have the solution. if you still use code that has an integer type. it's best to convert it to a string first like :

@client.on(ConnectEvent)
async def on_connect(event: ConnectEvent):
    print(f"Connected to @{str(event.unique_id)} (Room ID: {str(client.room_id)}")

maybe it can help a little

aCS6 commented 2 months ago

Thanks @zufarrizal For your observation. But that didn't help me, cause the error occurs directly into the package's code.

TikTokLive/client/web/routes/fetch_is_live.py",line 66, in

    return [i["alive"] for i in response_json["data"]]
isaackogan commented 2 months ago

Fixed 6.0.7