question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] - IndexError: list index out of range

See original GitHub issue

Description I’m trying to get the description of the videos of an user, it had worked for months until last week

code

from TikTokApi import TikTokApi
api = TikTokApi()

n_videos = 1000
username = 'crisbasabe'
user_videos = api.byUsername(username, count=n_videos)
import pandas as pd

def simple_dict(tiktok_dict):
  to_return = {}
  to_return['user_name'] = tiktok_dict['author']['uniqueId']
  to_return['user_id'] = tiktok_dict['author']['id']
  to_return['video_id'] = tiktok_dict['id']
  to_return['video_desc'] = tiktok_dict['desc']
  to_return['video_time'] = tiktok_dict['createTime']
  to_return['video_length'] = tiktok_dict['video']['duration']
  to_return['video_link'] = 'https://www.tiktok.com/@{}/video/{}?lang=en'.format(to_return['user_name'], to_return['video_id'])  
  to_return['n_likes'] = tiktok_dict['stats']['diggCount']
  to_return['n_shares'] = tiktok_dict['stats']['shareCount']
  to_return['n_comments'] = tiktok_dict['stats']['commentCount']
  to_return['n_plays'] = tiktok_dict['stats']['playCount']  
  return to_return


user_videos = [simple_dict(v) for v in user_videos]
user_videos_df = pd.DataFrame(user_videos)
user_videos_df.to_csv('{}_videos.csv'.format(username),index=False)

Usually ia csv file was created without issues

Error Trace )

# Traceback (most recent call last):
  File "c:/Users/John Mario/hello/tests/test_discover.py", line 7, in <module>
    user_videos = api.byUsername(username, count=n_videos)
  File "C:\Users\John Mario\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TikTokApi\tiktok.py", line 437, 
in byUsername
    data = self.getUserObject(username, **kwargs)
  File "C:\Users\John Mario\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TikTokApi\tiktok.py", line 1000, in getUserObject
    return self.getUser(username, **kwargs)["userInfo"]['user']
  File "C:\Users\John Mario\AppData\Local\Programs\Python\Python38-32\lib\site-packages\TikTokApi\tiktok.py", line 1030, in getUser
    j_raw = t.split('<script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">')[1].split("</script>")[0]
IndexError: list index out of range

Desktop (please complete the following information):

  • OS: Windows 10
  • TikTokApi Version 3.7.9

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
thanasakoscommented, Nov 18, 2020

Tried that from several different IPs as well, with same result.

3reactions
thanasakoscommented, Nov 18, 2020

I encounter a similar error with the getUser, and byUsername endpoints. I even tried with the custom_verifyFp from my browser session, and the problem persists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

List Index Out of Range – Python Error Message Solved
You'll get the Indexerror: list index out of range error when iterating through a list and trying to access an item that doesn't...
Read more >
Index Error: list index out of range (Python) - Stack Overflow
Generally it means that you are providing an index for which a list element does not exist. E.g, if your list was [1,...
Read more >
Python IndexError: List Index Out of Range [Easy Fix] - Finxter
The error “list index out of range” arises if you access invalid indices in your ...
Read more >
Indexerror: list Index Out of Range in Python - STechies
In the above case, the error occurs inline 5, as shown in output where print(list_fruits[i]) means that the value of “i” exceeds the...
Read more >
Python IndexError: List Index Out of Range Error Explained
What is the Python IndexError? ... We can break down the text a little bit. We can see here that the message tells...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found