該当エラー
Requesting data from TikTok
Traceback (most recent call last):
File "D:\desarrollo\tiktok\tiktokapi.py", line 39, in
for video in api.trending.videos():
File "C:\python\python390\lib\site-packages\TikTokApi\api\trending.py", line 40, in videos
ttwid = spawn.cookies["ttwid"]
File "C:\python\python390\lib\site-packages\requests\cookies.py", line 328, in getitem
return self._find_no_duplicates(name)
File "C:\python\python390\lib\site-packages\requests\cookies.py", line 399, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='ttwid', domain=None, path=None"
原因
2023年1月6日時点で未解決のバグ
https://github.com/davidteather/TikTok-Api/issues/979
コード
from TikTokApi import TikTokApi
import json
# read data from json file, cookie exported from webbrowser
def get_cookies_from_file():
with open('www.tiktok.com.cookies.json') as f:
cookies = json.load(f)
cookies_kv = {} # key-value
for cookie in cookies:
cookies_kv[ cookie['name'] ] = cookie['value']
print ( cookie['name'] + "=" + cookie['value'] )
return cookies_kv
print('Reading data from cookie file...')
cookies = get_cookies_from_file() #obtiene un dictionary key-value
def get_cookies(**kwargs):
return cookies
api = TikTokApi()
api._get_cookies = get_cookies
print(" Requesting data from TikTok")
for video in api.trending.videos():
print ( video.author.username)
↑以下の解決策とやろうとしていることは同じ
https://laboratory.kazuuu.net/get-the-latest-trending-videos-on-tiktok-using-tiktokapi-in-python/