You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the api.hashtag method, the API responses from a small percentage of videos don't have an 'author' field, resulting in the error KeyError: 'author'.
The buggy code
For example, retrieving videos that use the hashtag "juliusevola" results in the error:
We see on the TikTok website that when searching for that specific hashtag, there is indeed a video (id 7063900161278166533) that doesn't have an associated username. This may be because the creator was banned or their account was deleted.
Expected behavior
One video that doesn't have an associated username shouldn't cause the whole request to fail. If there is no associated username for a given video, a null value for the 'author' attribute seems like a reasonable choice.
Error Trace (if any)
Traceback (most recent call last):
File "<MY DIRECTORY>/mwe.py", line 15, in <module>
asyncio.run(fetch_hashtag_videos())
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "<MY DIRECTORY>/mwe.py", line 11, in fetch_hashtag_videos
async for video in api.hashtag(name = 'juliusevola').videos(count = 1000):
File "<MY VIRTUAL ENVIRONMENT>/lib/python3.9/site-packages/TikTokApi/api/hashtag.py", line 131, in videos
yield self.parent.video(data=video)
File "<MY VIRTUAL ENVIRONMENT>/lib/python3.9/site-packages/TikTokApi/api/video.py", line 60, in __init__
self.__extract_from_data()
File "<MY VIRTUAL ENVIRONMENT>/lib/python3.9/site-packages/TikTokApi/api/video.py", line 191, in __extract_from_data
author = data["author"]
KeyError: 'author'
Desktop (please complete the following information):
OS: Ubuntu 20.04
TikTokApi Version: 6.1.1
Additional context
The issue appears to be straightforward, changing line 191 of TikTokApi/api/video.py in __extract_from_data from author = data["author"] to author = data.get("author") fixes this problem.
The text was updated successfully, but these errors were encountered:
Describe the bug
When using the
api.hashtag
method, the API responses from a small percentage of videos don't have an'author'
field, resulting in the errorKeyError: 'author'
.The buggy code
For example, retrieving videos that use the hashtag "juliusevola" results in the error:
We see on the TikTok website that when searching for that specific hashtag, there is indeed a video (id 7063900161278166533) that doesn't have an associated username. This may be because the creator was banned or their account was deleted.
Expected behavior
One video that doesn't have an associated username shouldn't cause the whole request to fail. If there is no associated username for a given video, a null value for the 'author' attribute seems like a reasonable choice.
Error Trace (if any)
Desktop (please complete the following information):
Additional context
The issue appears to be straightforward, changing line 191 of TikTokApi/api/video.py in
__extract_from_data
fromauthor = data["author"]
toauthor = data.get("author")
fixes this problem.The text was updated successfully, but these errors were encountered: