question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`TikTok blocks this request displaying a Captcha` even with `custom_verifyFp` and `proxy`

See original GitHub issue

Everything was fine until last few days.

from TikTokApi import TikTokApi
import json
import logging
tiktok_api = TikTokApi.get_instance(request_delay=1)

tiktoks = tiktok_api.by_username('japanontiktok', count=1, custom_verifyFp="...", proxy='http://...', use_test_endpoints=True)

for tiktok in tiktoks[:1]:
    print(json.dumps(tiktok))

Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1333, in get_user
    j_raw = self.__extract_tag_contents(r.text)
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1553, in __extract_tag_contents
    nonce = html.split(nonce_start)[1].split(nonce_end)[0]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests.py", line 220, in <module>
    tiktoks = tiktok_api.by_username('japanontiktok', count=1, custom_verifyFp="...", proxy='http://...', use_test_endpoints=True)
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 700, in by_username
    data = self.get_user_object(username, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1301, in get_user_object
    return self.get_user(username, **kwargs)["userInfo"]["user"]
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1339, in get_user
    raise TikTokCaptchaError()
TikTokApi.exceptions.TikTokCaptchaError: TikTok blocks this request displaying a Captcha 
Tip: Consider using a proxy or a custom_verifyFp as method parameters

The most interesting thing there is that I can partly see obtained data from TikTok because its print HTML page in console before the error. You can see full response here: https://gist.githubusercontent.com/kostyakoz/1d5a7339217d646f1556d9fd63bcf7a8/raw/b18f4ae5e869325bb746c48fae102c8786b43fdb/error.py

My question is why obtained data not returned and I have only error?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

22reactions
Daan-Grashoffcommented, Jan 4, 2022

I’ve made a quick dirty fix for the meantime, works a lot better since they moved from next to sigi.

https://github.com/Daan-Grashoff/TikTok-Api

You can simply install it by using pip git+https://github.com/Daan-Grashoff/TikTok-Api.

Thanks @joseantgv for pointing out where it goes wrong!

4reactions
joseantgvcommented, Jan 3, 2022

Everything was fine until last few days.

from TikTokApi import TikTokApi
import json
import logging
tiktok_api = TikTokApi.get_instance(request_delay=1)

tiktoks = tiktok_api.by_username('japanontiktok', count=1, custom_verifyFp="...", proxy='http://...', use_test_endpoints=True)

for tiktok in tiktoks[:1]:
    print(json.dumps(tiktok))

Error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1333, in get_user
    j_raw = self.__extract_tag_contents(r.text)
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1553, in __extract_tag_contents
    nonce = html.split(nonce_start)[1].split(nonce_end)[0]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "tests.py", line 220, in <module>
    tiktoks = tiktok_api.by_username('japanontiktok', count=1, custom_verifyFp="...", proxy='http://...', use_test_endpoints=True)
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 700, in by_username
    data = self.get_user_object(username, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1301, in get_user_object
    return self.get_user(username, **kwargs)["userInfo"]["user"]
  File "/usr/local/lib/python3.8/dist-packages/TikTokApi/tiktok.py", line 1339, in get_user
    raise TikTokCaptchaError()
TikTokApi.exceptions.TikTokCaptchaError: TikTok blocks this request displaying a Captcha 
Tip: Consider using a proxy or a custom_verifyFp as method parameters

The most interesting thing there is that I can partly see obtained data from TikTok because its print HTML page in console before the error. You can see full response here: https://gist.githubusercontent.com/kostyakoz/1d5a7339217d646f1556d9fd63bcf7a8/raw/b18f4ae5e869325bb746c48fae102c8786b43fdb/error.py

My question is why obtained data not returned and I have only error?

If you save the response as HTML and open it in a browser, you will see that there’s information about the profile. I think that it’s a parse problem, maybe TikTok has changed the structure.

If you search for SIGI_STATE you will see a JSON object which already contains all the information.

image

image

It’s used this function to get the data:

def __extract_tag_contents(self, html):
    nonce_start = '<head nonce="'
    nonce_end = '">'
    nonce = html.split(nonce_start)[1].split(nonce_end)[0]
    j_raw = html.split(
        '<script id="__NEXT_DATA__" type="application/json" nonce="%s" crossorigin="anonymous">'
        % nonce
    )[1].split("</script>")[0]
    return j_raw

and can’t find <script id="__NEXT_DATA__" type="application/json" nonce="%s" crossorigin="anonymous">' in the response.

I think that this could be the clue: https://git.raptorpond.com/henine/yt-dlp/commit/11aa91a12f95821500fa064402a3e2c046b072fb

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix TikTok blocks this request displaying a Captcha #421
TikTok blocks this request displaying a Captcha ERROR:root:Tiktok wants ... Have the same issue with api v3.8.6 even using custom_verifyFp ...
Read more >
how to create a good verifyfp for TikTok-Api to bypass captcha ...
how to create a good verifyfp for TikTok -Api to bypass captcha errordiscord : discord.gg/kpoppaypal : https://www.paypal.me/ksinging.
Read more >
Captcha error with Python TikTokApi (from davidteather)
TikTokCaptchaError : TikTok blocks this request displaying a Captcha Tip: Consider using a proxy or a custom_verifyFp as method parameters.
Read more >
reCAPTCHA Help - Google Support
A “CAPTCHA” is a turing test to tell human and bots apart. It is easy for humans to solve, but hard for “bots”...
Read more >
tiktok-captcha-solver - npm
Solves the TikTok captcha interactively using playwright or puppeteer.. Latest version: 0.0.9, last published: 8 months ago.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found