Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
0xSFAYGA opened this issue Dec 1, 2022 · 18 comments
Closed

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

0xSFAYGA opened this issue Dec 1, 2022 · 18 comments
Labels
bug Something isn't working

Comments

@0xSFAYGA
Copy link

0xSFAYGA commented Dec 1, 2022

Hi i try am may ways to slove the problem .

File "/home/me/Tk/main.py", line 29, in <module> 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"

@0xSFAYGA 0xSFAYGA added the bug Something isn't working label Dec 1, 2022
@MinoBanana
Copy link

I have the same error

@0xSFAYGA
Copy link
Author

0xSFAYGA commented Dec 3, 2022

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
Copy link

NorthernLightx commented Dec 5, 2022

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
Copy link
Author

0xSFAYGA commented Dec 5, 2022

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
Copy link

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
Copy link

Any updates about this issue?

@hamouddd
Copy link

any fix??

@vinivitin
Copy link

Any updates?

@bilalcancode
Copy link

same issue here!

@Kamushy
Copy link

Kamushy commented Jan 4, 2023

and updates

@jeancc
Copy link

jeancc commented Jan 5, 2023

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
Copy link

Same issue on Python 3.8 and 3.11

@verfluecht
Copy link

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
Copy link

ColdFire87 commented Jan 21, 2023

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
Copy link

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

@leoleepsyche
Copy link

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

@hamouddd
Copy link

hamouddd commented May 29, 2023 via email

@davidteather
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

16 participants