davidteather / TikTok-Api

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

How to fix TikTok blocks this request displaying a Captcha #421

Closed Noraluk closed 3 years ago

Noraluk commented 3 years ago

TikTok blocks this request displaying a Captcha

ERROR:root:Tiktok wants to display a catcha. Response is:

{"code":"10000","from":"","type":"verify","version":"","region":"va","subtype":"slide","detail":"fYVaOXdGHrwkYZYogUmYdBY8-FJlzSK13HPPFk4iPsmeRax8twpZOScClv9WuKaaV1CNaF6wJ7qKHfg9BoeJkiXwJZGdeM8NPN3hrQmhf0q5axln1rDo1POPgnK931e-5QMRPPN4whuZe1inHPx-JrPPejeXLVXzYz1sRjR5LUMfwNfZzU9-waptDR1A6gaFzDBrWj73by6FC2xDT-EPS-iBEoSes7zLU-eEnXfEIdj22InYwoGGD-qkHAifa7VE6JLSDPwRcAAusKzYmZUeCiGnLYyBTZidNYGerH","verify_event":"","fp":"verify_kinzszck_diuaRMsk_SeQi_4nHI_AEOX_WnWV8BwhwBK","scene":""}

ERROR:root:{'tt_webid': '0903287986343365897', 'tt_webid_v2': '0903287986343365897', 'tt_csrf_token': 'qVRgzrYYbdQiNNUE'}

Tip: Consider using a proxy or a custom_verifyFp as method parameters

jhaskinsPhD commented 3 years ago

I've also been running into this problem. I solved it (briefly) by logging into TikTok on my browser (Chrome) going to Cookies and finding the variable s_v_web_id, copy and pasting that into the custom_verifyFp='longcookiename'. It worked for 3-4 times as I debugged my code then it started popping this error again. Apparently this Cookie updates each time you browse and TikTok was fast enough at catching on that I was a bot after a few uses of the workaround.... This solution no longer works for me (even with an updated s_v_web_id cookie variable).

Edit to add: I also already downloaded the update (today) from last week's issue citing this.

Incher25 commented 3 years ago

Have the same issue with api v3.8.6 even using custom_verifyFp parameter.

reccardt commented 3 years ago

I'm wondering if it recognizes the browser after a while. It worked for me for days using Chrome Incognito mode, loading tiktok.com but not signing in, loading the captcha page in another tab, solving it and getting the cookie from developer tools. I couldn't get it to work today. I tried a different machine at a different IP address and the same procedure did work. I'll go back to the first machine tomorrow or the next day to see if it recovers.

davidteather commented 3 years ago

Try the following api = TikTokApi(use_api_endpoints=True) it uses TikTok's test endpoints which seem to have less security. Their entire desktop site on the trending page is having issues right now.

Incher25 commented 3 years ago

Try the following api = TikTokApi(use_api_endpoints=True) it uses TikTok's test endpoints which seem to have less security. Their entire desktop site on the trending page is having issues right now.

I tried to do this but get the following error:

ERROR:root:TikTok response: { statusCode: -1, itemInfo: {} } ERROR:root:Converting response to JSON failed ERROR:root:Expecting property name enclosed in double quotes: line 2 column 5 (char 6) Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/TikTokApi/tiktok.py", line 196, in getData json = r.json() File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 892, in json self.content.decode(encoding), **kwargs File "/usr/lib/python3.7/json/init.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 5 (char 6)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/var/www/adchek/deployer_build/releases/423/app/../python/scripts/TikTok/get_tiktok_by_id.py", line 13, in tiktok = json.dumps(api.getTikTokById(id=tiktokId)) File "/usr/local/lib/python3.7/dist-packages/TikTokApi/tiktok.py", line 999, in getTikTokById return self.getData(url=api_url, **kwargs) File "/usr/local/lib/python3.7/dist-packages/TikTokApi/tiktok.py", line 217, in getData raise JSONDecodeFailure() from e TikTokApi.exceptions.JSONDecodeFailure: TikTok sent invalid JSON back

davidteather commented 3 years ago

@Incher25 are you using selenium?

Incher25 commented 3 years ago

@davidteather no, but if I use selenium I get "FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'" error

noraluk-scg commented 3 years ago

Although I use api = TikTokApi(use_api_endpoints=True), I get the captcha block again

Incher25 commented 3 years ago

Now I run "api = TikTokApi.get_instance(use_api_endpoints=True)" (without my custom_verifyFp and via playwright) and it seems getTikTokById() works fine for now. Maybe I should get new custom_verifyFp from browser.

reccardt commented 3 years ago

@davidteather Thanks for all the great work you do. Did you mean use_test_endpoints=True instead of use_api_endpoints=True? I've been using https://t.tiktok.com/ as the BASE_URL all along. The problem I had yesterday seems to be gone; even my problem machine is able to call trending successfully. Maybe I just have to be more persistent.

davidteather commented 3 years ago

Yeah I meant use_test_endpoints sorry about that. I'd also advise everyone who is having issues with this API to start using a proxy & make sure your IP isn't banned from TikTok because I know some people who got their residential IP banned from TikTok

davidteather commented 3 years ago

You definitely should be able to get the use_test_endpoints=True to request a lot of data using something like luminati.io as a proxy

davidteather commented 3 years ago

There's also a YouTube video in the readme that explains how to get a custom_verifyFp and another workaround

jrdutra commented 2 years ago

Hey, use_test_endpoints=True worked for me by this moment...

sanghavp commented 2 years ago

I have tried to follow all the solutions mentioned above but when I do it sometimes it succeeds sometimes it fails. while my source code has not changed.

wrogers3 commented 2 years ago

I have tried to follow all the solutions mentioned above but when I do it sometimes it succeeds sometimes it fails. while my source code has not changed.

same here, what would be the culprit then?

StathisKap commented 1 year ago

I know there is a chrome extension called nopeCha that solves capchas for you. It's paid software but maybe there is an open source alternative that could be used to just solved the tiktok capchas?