davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.71k stars 956 forks source link

KeyError: "name='ttwid', domain=None, path=None" #979

Closed 0xSFAYGA closed 1 year ago

0xSFAYGA commented 1 year ago

Hi i try am may ways to slove the problem .

`File "/home/me/Tk/main.py", line 29, in for trending_video in api.trending.videos(count=5): File "/home/me/Tk/env/lib/python3.11/site-packages/TikTokApi/api/trending.py", line 40, in videos ttwid = spawn.cookies["ttwid"]


  File "/home/devy/Tk/env/lib/python3.11/site-packages/requests/cookies.py", line 334, in __getitem__
    return self._find_no_duplicates(name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/me/Tk/env/lib/python3.11/site-packages/requests/cookies.py", line 413, in _find_no_duplicates
    raise KeyError(f"name={name!r}, domain={domain!r}, path={path!r}")
KeyError: "name='ttwid', domain=None, path=None"`
MinoBanana commented 1 year ago

I have the same error

0xSFAYGA commented 1 year ago

in this location try to change hearders .

File "/home/me/Tk/env/lib/python3.11/site-packages/TikTokApi/api/trending.py

spawn = requests.head(
            "https://www.tiktok.com",
            proxies=Trending.parent._format_proxy(processed.proxy),
            **Trending.parent._requests_extra_kwargs,
            headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36"}
                )
NorthernLightx commented 1 year ago

Can confirm, I have also this issue from this:

from TikTokApi import TikTokApi

verify_fp='...'
api = TikTokApi(custom_verify_fp=verify_fp)

for video in api.trending.videos(count=5):
    print(video.id)

The suggestion from @souffyan does not seem to help - the error dissapears, but the code is freezing and does not return anything.

0xSFAYGA commented 1 year ago

Can confirm, I have also this issue from this:

from TikTokApi import TikTokApi

verify_fp='...'
api = TikTokApi(custom_verify_fp=verify_fp)

for video in api.trending.videos(count=5):
    print(video.id)

The suggestion from @souffyan does not seem to help - the error dissapears, but the code is freezing and does not return anything.

me to .

ArthurKun21 commented 1 year ago
from TikTokApi import TikTokApi

with TikTokApi() as api:
    user = api.user(username="therock")
    for video in user.videos():
        print(video.id)

I've tested the one from the example, and also getting the same error

sarzixon commented 1 year ago

Any updates about this issue?

hamouddd commented 1 year ago

any fix??

vinivitin commented 1 year ago

Any updates?

bilalcancode commented 1 year ago

same issue here!

Kamushy commented 1 year ago

and updates

jeancc commented 1 year ago

Same problem here.

This is the code (including the cookie):

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)

The output:

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"

aplinefresh commented 1 year ago

Same issue on Python 3.8 and 3.11

verfluecht commented 1 year ago

Having the same issue on all my systems: Windows 11 with Python 3.11, Windows 10 with Python 3.10 and MacOS Venture 13.0.1 with Python 3.11.1

ColdFire87 commented 1 year ago

Same issue on macOS Big Sur, Python 3.8, TikTokApi==5.2.2

spawn = requests.head(
            "https://www.tiktok.com",
            proxies=Trending.parent._format_proxy(processed.proxy),
            **Trending.parent._requests_extra_kwargs,
        )

        with open("cookies.txt", "w") as file:
            file.write(str(spawn.cookies.keys()))

cookies.txt

['_abck', 'bm_sz']
verfluecht commented 1 year ago

Does anyone know if this issue is present in older versions? If not, maybe it makes sense downgrading for the moment.

leoleepsyche commented 1 year ago

also the same problem. is anyone managed to fix it? please let me know.

hamouddd commented 1 year ago

I had the same problem but basically I was trying to download videos and get some of the video data so I found a better library that would do this for me:

https://github.com/Evil0ctal/Douyin_TikTok_Download_API

If you look into the scraper.py file you will see the functions that you need to do this and basically all you gotta do is get the video id from the url using the built in function and then you get video data using the video id using the other built in function. Look at their readme.md page to see how they used asyncio and all that. When you get the video data it's just a massive dictionary that you can look through and get exactly what you want from it. It will have links to where you can download the video information.

Hope this helps.

On Fri, May 26, 2023 at 5:02 PM Geng Liu @.***> wrote:

also the same problem. is anyone managed to fix it? please let me know.

— Reply to this email directly, view it on GitHub https://github.com/davidteather/TikTok-Api/issues/979#issuecomment-1564948570, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYTU533KAK45UKYQNKPRTSTXIEK7HANCNFSM6AAAAAASQKSTHU . You are receiving this because you commented.Message ID: @.***>

davidteather commented 1 year ago

Should be fixed in V6 I think it shouldn't load cookies directly anymore