TikTok-Api icon indicating copy to clipboard operation
TikTok-Api copied to clipboard

[BUG] - KeyError: "name='ttwid', domain=None, path=None"

Open rachmadrinaldie opened this issue 3 years ago • 20 comments

So I was trying to get user videos and I try to follow the example code :

from TikTokApi import TikTokApi

verify_fp = "verify_xxx"
# Notes : im using my own verify_fp

api = TikTokApi(custom_verify_fp=verify_fp)

user = api.user(username="therock")

for video in user.videos():
    print(video.id)

Expected behavior

List of user videos based on username I wrote.

Error Trace (if any)

Traceback (most recent call last):
  File "/home/rachmadrin/api-social-media/testing_tiktok.py", line 10, in <module>
    for video in user.videos():
  File "/home/rachmadrin/venv-kolabora/lib/python3.8/site-packages/TikTokApi/api/user.py", line 133, in videos
    self.__find_attributes()
  File "/home/rachmadrin/venv-kolabora/lib/python3.8/site-packages/TikTokApi/api/user.py", line 263, in __find_attributes
    for u in self.parent.search.users(self.username):
  File "/home/rachmadrin/venv-kolabora/lib/python3.8/site-packages/TikTokApi/api/search.py", line 85, in search_type
    ttwid = spawn.cookies["ttwid"]
  File "/home/rachmadrin/venv-kolabora/lib/python3.8/site-packages/requests/cookies.py", line 328, in __getitem__
    return self._find_no_duplicates(name)
  File "/home/rachmadrin/venv-kolabora/lib/python3.8/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"

Notes : it's still do the same error even if I didn't use custom_verify_fp anymore

Environment:

  • OS: Ubuntu 20.04
  • TikTokApi Version 5.0.0

rachmadrinaldie avatar Mar 02 '22 03:03 rachmadrinaldie

I get this too

3dian avatar Mar 02 '22 15:03 3dian

I get this too

SegevSolomon avatar Mar 02 '22 16:03 SegevSolomon

I get this too

maksam07 avatar Mar 06 '22 08:03 maksam07

I get this too, docker run

bjtuweb-12281047 avatar Mar 08 '22 12:03 bjtuweb-12281047

I get this too

Kreimen123 avatar Mar 10 '22 15:03 Kreimen123

这个问题解决了么

mengguiyouziyi avatar Mar 14 '22 12:03 mengguiyouziyi

这个问题解决了么

until today these issues still happen, dude.

直到今天,这个问题仍然发生,伙计。

@mengguiyouziyi

rachmadrinaldie avatar Mar 15 '22 03:03 rachmadrinaldie

Same here. Going back to 4.1.0 for now.

jp-wagner avatar Mar 19 '22 22:03 jp-wagner

Same here. Going back to 4.1.0 for now.

do the older versions work?

wrogers3 avatar Mar 20 '22 12:03 wrogers3

i get the above terminal prompt too

wrogers3 avatar Mar 20 '22 12:03 wrogers3

I get this too

419606974 avatar Mar 22 '22 07:03 419606974

I too, version 5.1.1

pashokitsme avatar Mar 23 '22 05:03 pashokitsme

Same, version 5.1.1

Tempest042 avatar Mar 24 '22 01:03 Tempest042

Same here. Going back to 4.1.0 for now.

The same error appears in v4.1.0 as well for me

hmoazam avatar Mar 24 '22 07:03 hmoazam

I get this too.

Windows 11 version 5.1.1

nickkarp avatar Mar 25 '22 03:03 nickkarp

Hi, I have the same problem with both 4.1.0 and 5.1.1. I haven't installed "chromedriver globally" because i'm not the machine administrator, but in this machine i use python scripts with selenium and ChromeDriverManager without issues:

# Initialize a new browser
def start_chrome_driver(url, wait=30):
    """
    create an instance of selenium Chrome
    :param url: the url of the site to connect to
    :type url: string
    :param wait: seconds to wait
    :type wait: int
    :return: driver
    :rtype: webdriver.Chrome
    """

    user_data_dir = f"{os.getcwd()}\\UserData"
    os.makedirs(os.path.dirname(user_data_dir), exist_ok=True)
    sys.path.append(user_data_dir)

    options = Options()
    options.headless = True
    options.add_argument("--window-position=10,10")
    options.add_argument('--user-agent=Chrome/79.0.3945.130 Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                         'AppleWebKit/537.36 (KHTML, like Gecko) ')
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-extensions")
    options.add_argument("--disable-gpu")
    options.add_argument("--disable-d3d11")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument(f'user-data-dir={user_data_dir}')

    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    driver.implicitly_wait(wait)
    driver.get(url)
    return driver

StefanoGITA avatar May 11 '22 15:05 StefanoGITA

+1, not working

miholeus avatar May 18 '22 09:05 miholeus

Same here

looCiprian avatar Jun 07 '22 09:06 looCiprian

Same here

Monteleone avatar Jun 20 '22 17:06 Monteleone

This suggestion solves the ttwid error but then there's a CaptchaException: https://github.com/davidteather/TikTok-Api/issues/890#issuecomment-1145724326

dylancaponi avatar Aug 16 '22 00:08 dylancaponi

+1

Arax250190 avatar Sep 25 '22 19:09 Arax250190

same issue here

njraladdin avatar Sep 27 '22 22:09 njraladdin

+1

Tracer-Shield avatar Oct 10 '22 03:10 Tracer-Shield

Is anyone got any solution ?

bilalahmedkhatri avatar Oct 11 '22 14:10 bilalahmedkhatri

Same here

PierreBregeard avatar Nov 02 '22 21:11 PierreBregeard

same problem here

Debangsha1992 avatar Nov 18 '22 04:11 Debangsha1992

Same for me. It seems that there is anti-bot mechanism which adds _abck and bm_sz cookies at the beginning. (https://security.stackexchange.com/questions/182895/anti-bot-javascript-library-identification). TikTok-Api uses requests lib to call http://www.tiktok.com to get ttwid cookie but anti-bot tool detects that it's not a human and returns 403 code without attaching ttwid. You can check it by returning status code just before this line: https://github.com/davidteather/TikTok-Api/blob/master/TikTokApi/api/search.py#L85 I suppose real request from the browser (e.g. via selenium) for the first call would resolve the issue. I'm able to retrieve ttwid with Postman's call.

jc-a3s avatar Nov 20 '22 22:11 jc-a3s

+1

helloeveryworlds avatar Dec 12 '22 07:12 helloeveryworlds

+1

fiott248 avatar Dec 17 '22 16:12 fiott248

So It doesn't work ?

oknehcnap avatar Dec 31 '22 00:12 oknehcnap