TikTok-Api: `TikTok blocks this request displaying a Captcha` even with `custom_verifyFp` and `proxy`
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?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (2 by maintainers)
Commits related to this issue
- Initial changes for v5 of the project. Initial changes for v5 of the project. Thanks @Daan-Grashoff for some of the helpers.extract_tag_contents code from a comment on #787 Co-Authored-By: Daan Gra... — committed to davidteather/TikTok-Api by davidteather 2 years ago
- 🎊 V5.0.0 🎊 (#803) * Initial changes for v5 of the project. * Thanks @Daan-Grashoff for some of the helpers.extract_tag_contents code from a comment on #787 * High Level Modeling of Classes ... — committed to davidteather/TikTok-Api by davidteather 2 years ago
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!
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_STATEyou will see a JSON object which already contains all the information.It’s used this function to get the data:
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
I am facing the same problem as well. It was working fine with custom_verifyFp earlier. But, I think a week ago, it starts breaking. Today, I run the by.username() in loop until it succeeded with custom_verifyFp and it worked once after each 20-30 tries. Sometimes changing proxy also helps but I think there is some issue with API. I have the exact same error as @kostyakoz Showed above.
Thanks for the fix! Works flawlessly, but would it be possible to return the Likes, Followers & Following count for a user?