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

[BUG] - TikTok blocks this request displaying a Captcha #627

Closed Alex-Laparra closed 3 years ago

Alex-Laparra commented 3 years ago

Description of the bug Systematic captcha error when using by_username method. Error message advises using proxy or a custom_verifyFp but this bug would also appear after a while in previous versions for which I had tried using proxy or a custom_verifyFp without success until a new version eventually fixed this issue. And this has happened quite a few times actually so I suppose you might know how to fix it again now. When you do, I'd be glad if you could explain how you did it, so I can fix it myself in the future and upload pull request quickly since I use your API on a daily basis.

The buggy code

from TikTokApi import TikTokApi as t
api = t.get_instance()
k = api.by_username("")

Error Trace

ERROR:root:Tiktok wants to display a catcha. Response is:
{"code":"10000","from":"","type":"verify","version":"","region":"va","subtype":"slide","detail":"GDIqyl9SLA5lVSsn4JVxPJ2cYRgDuhDP2NBDA0FqMagtMGQB8TGV2kpodkbZzjHKYcgIzsCRQbF60HRg3l9Qauc2Do6mMa-0Zg5zDKWegm2X6nPmvd0*iT3sZKcm1jeSXuYDR8MliQ8C-w5slo0ucQ-I1mouIfpZAPBvtuqCaLlitjnBe-x9821RxB7KI1poAlO19vIyMqX4daxORf7eHrqKoJv7CA03WhiLzQT0*0mhfkO1deNBCczMZ6SIL6hTp6aUbCoqz51dHuiKM-cGG*WHzU*snEBYxNaixbl84PVCwRqDYF1byBZiBDJ8jU50uDiiJ53EL3dtYdXtcoWBr6Q8F1Cly-FTFBOuwusDQEbR*bKMA23oExlFHGvq2mAlpYmzG*v-6mvF64wPNe1i1xh-qHQPS3zWJxo.","verify_event":"","fp":"verify_khr3jabg_V7ucdslq_Vrw9_4KPb_AJ1b_Ks706M8zIJTq","scene":"","verify_ticket":"","channel_mobile":"","sms_content":"","mobile":"","email":""}
ERROR:root:{'tt_webid': '1637611630395385016', 'tt_webid_v2': '1637611630395385016', 'csrf_session_id': '13d94c933ff245fd8bf4696164422b16', 'tt_csrf_token': 'vAtEBuHpdiZmCVUk'}
Traceback (most recent call last):
  File "C:\Users\me\Documents\0_Projet\herer\testt\bug.py", line 4, in <module>
    k = api.by_username(us)
  File "C:\Users\me\AppData\Roaming\Python\Python37\site-packages\TikTokApi\tiktok.py", line 603, in by_username
    **kwargs,
  File "C:\Users\me\AppData\Roaming\Python\Python37\site-packages\TikTokApi\tiktok.py", line 563, in user_posts
    res = self.get_data(url=api_url, **kwargs)
  File "C:\Users\me\AppData\Roaming\Python\Python37\site-packages\TikTokApi\tiktok.py", line 279, in get_data
    raise TikTokCaptchaError()
TikTokApi.exceptions.TikTokCaptchaError: TikTok blocks this request displaying a Captcha 
Tip: Consider using a proxy or a custom_verifyFp as method parameters

Desktop

kpopdev commented 3 years ago

please fix it i have same problem. im using proxies too.

alanblue2000 commented 3 years ago

Have you seen this, his tutorial, https://www.youtube.com/watch?v=zwLmLfVI-VQ&t=117s Let us know if you get it working

Alex-Laparra commented 3 years ago

Have you seen this, his tutorial, https://www.youtube.com/watch?v=zwLmLfVI-VQ&t=117s Let us know if you get it working

doesn't work

felixwann commented 3 years ago

same

lafritte57 commented 3 years ago

Same thing here, I tried with different s_v_web_id cookie values but also with several proxies and the problem persists.

dylancaponi commented 3 years ago

I think TikTok has made another change. 3.9.9 fixed things for 12 days but now byUsername is triggering captcha response again while getUser is not. Same verifyfp, same code.

kpopdev commented 3 years ago

i think we can bypass this but im still not sure https://2captcha.com/blog/tiktok-captcha

Alex-Laparra commented 3 years ago

I think TikTok has made another change. 3.9.9 fixed things for 12 days but now byUsername is triggering captcha response again while getUser is not. Same verifyfp, same code.

Exactly what I was thinking, tiktok keeps changing their verification methods, it's very annonying. I'll try to look into it and see if I can fix it myself, but I've only started learning coding recently so it might take me some time.

Alex-Laparra commented 3 years ago

i think we can bypass this but im still not sure https://2captcha.com/blog/tiktok-captcha

Haven't looked into it that much yet, but if it works, David should definitely implement it.

Alex-Laparra commented 3 years ago

It seems to work just fine right now. I'm gonna leave this issue open for 24 more hours just in case it gets buggy again.

Edit: doesn't work anymore.

kpopdev commented 3 years ago

did u changed your code? tell us too

Alex-Laparra commented 3 years ago

did u changed your code? tell us too

Haven't changed anything, it just works now for some reason. Try to chek with your code, should work too.

lafritte57 commented 3 years ago

It seems to work just fine right now. I'm gonna leave this issue open for 24 more hours just in case it gets buggy again.

On my side it still doesn't work... Are you using a different proxy or something?

aecollier commented 3 years ago

Hello! I've been following along with this issue hoping to solve mine, but no luck. I haven't been able to scrape in two weeks without getting this Captcha error. I've tested with and without the custom_verify_Fp, and used the custom_verify_Fp at both the instance and method levels. I've tried running on different networks, I've completely cleared my cache and gotten new sv_web_id values immediately before running code, and it's not working with any api methods I've called (I'm working with trending, by_hashtag, by_username, by_sound). My api wasn't up to date at first but also hasn't worked since updating. Haven't tried a proxy but have run on a separate VPN connection. Here's the buggy code, hopefully someone will have some leads on this!

from TikTokApi import TikTokApi

v = 'verify_kqb4t0nl_WmfI8Wsi_AiNx_4n2Z_AQFq_vVMh9w32JL5j'

api = TikTokApi.get_instance(custom_verifyFp = v, use_test_endpoints = True) # tried with the custom_verifyFp here and also below

results = 100
hashtag = 'indigenous'
full_dic = api.by_hashtag(custom_verifyFp = v, hashtag = hashtag,count = results)
print(full_dic)

Error trace:

ERROR:root:Tiktok wants to display a catcha. Response is:
{"code":"10000","from":"","type":"verify","version":"","region":"sg","subtype":"slide","detail":"ddBIW77iQIGYBZs6RBnY5rBpJWJi0QzTtLwlZhscdiZuhe7Ea43v0BEX*VdbeqHY41OLa48BynjJXyO*rtvmNTRBtHqIdXUVVVZ7ZThHV7OKrypjFny3lYK3v6VKKDO7m-4FBayOhGh*09GJ1VwWZzs3mBb64KeWo3UwtgjlIkD5yc-2p73pw6sYi5JW7skWGK0XEgXdyVfhF9V1KNvJiGgvBn3e1n7jJ-5J*TQhkmBd3eu*RCuSb1Q79qNOcNxCI9pBWlRJl*7hcNpW7DmY*QbfSFPAnFe2cBL7UBFrml7-mNsz4FYorbw9SK4cAWAvoohiCH8cWA9jIIriPUKw*kkHxoQoWcaUTggmofQTZdlrSNb1uBOLPKDS3iDMMUk-HR6H1mXnl283sXhOf922qpjcnB3tHluBMeCt8--E8w..","verify_event":"","fp":"verify_kqb4t0nl_WmfI8Wsi_AiNx_4n2Z_AQFq_vVMh9w32JL5j","scene":"","verify_ticket":"","channel_mobile":"","sms_content":"","mobile":"","email":""}
ERROR:root:{'tt_webid': '1833549081721455987', 'tt_webid_v2': '1833549081721455987', 'tt_csrf_token': 'OSiTkdwdOxAyifVt'}
Traceback (most recent call last):
  File "C:\Users\abiga\Documents\TikTok_Analysis\hashtag.py", line 16, in <module>
    full_dic = api.by_hashtag(custom_verifyFp = v, hashtag = hashtag,count = results)
  File "C:\Users\abiga\Documents\TikTok_Analysis\TikTokApi\tiktok.py", line 915, in by_hashtag
    res = self.getData(url=api_url, **kwargs)
  File "C:\Users\abiga\Documents\TikTok_Analysis\TikTokApi\tiktok.py", line 270, in get_data
    raise TikTokCaptchaError()
TikTokApi.exceptions.TikTokCaptchaError: TikTok blocks this request displaying a Captcha
Tip: Consider using a proxy or a custom_verifyFp as method parameters
Alex-Laparra commented 3 years ago

It seems to work just fine right now. I'm gonna leave this issue open for 24 more hours just in case it gets buggy again.

On my side it still doesn't work... Are you using a different proxy or something?

It worked for a short period of time but doesn't work anymore I'm afraid

Alex-Laparra commented 3 years ago

Still not working as of now

kpopdev commented 3 years ago

@Alex-Laparra this will fix all captcha errors https://youtu.be/MgjorCvPzxg just watch it. im using firefox btw but i think on other Web browsers works too.

Alex-Laparra commented 3 years ago

@Alex-Laparra this will fix all captcha errors https://youtu.be/MgjorCvPzxg just watch it. im using firefox btw but i think on other Web browsers works too.

Hey! First thing thanks! I'm doing everything you're doing in the tutorial but when I click on an other music link after deleting all the cookies, I'm not getting a captcha and I'm using Firefox too. But would there be a way to automate this? I'm currently in the process of creating an app using this api and this process is bit laborious for a random user so it'd be better if the problem were to be fixed at the source because at some times the verifyFp wasn't needed and then Tiktok changed stuff with their servers and David or some guy with a pull request would fix the problem but then the problem would appear again and this has happened many many times already. So a permanent fix would be so cool. I'm gonna try and look at the code to fix it myself but I mean I've just recently started coding recently so I might not find a solution. But thanks again for your kind help!

kpopdev commented 3 years ago

on Discover click on a music image also you have to be already on a music link then delete your cookies. it will show you the captcha and do the captcha and copy it.

Alex-Laparra commented 3 years ago

on Discover click on a music image also you have to be already on a music link then delete your cookies. it will show you the captcha and do the captcha and copy it.

I've repeated this process like ten times but I'm not getting the captcha, when i click on a an other music link, it directly takes me to that page

kpopdev commented 3 years ago

if you delete your cookies from tiktok.com you will get captcha always. use this verify_f59ff756e4e331c2b798fb7b4928c6de also do u have discord?

kpopdev commented 3 years ago

when you dont get captcha it means you didnt delete your cookies.

Alex-Laparra commented 3 years ago

if you delete your cookies from tiktok.com you will get captcha always. use this verify_f59ff756e4e331c2b798fb7b4928c6de also do u have discord?

Well I can swear to you i'm not getting any captcha 😂. Yes my discord is Twelvanoff#9987. Thanks for the verifyFp, will try it now

Alex-Laparra commented 3 years ago

when you dont get captcha it means you didnt delete your cookies.

But i did

kpopdev commented 3 years ago

That verifyfp works or not?

Alex-Laparra commented 3 years ago

Your verifyFp works fine thanks. How long does it usually last?

kpopdev commented 3 years ago

see? it will work just delete all your cookies then. go to this website about:preferences#privacy then go to the manage data... and then search for tiktok and then click on remove all shown and then save changes and then once again click on remove. also dont close the tiktok music link when you are deleting your cookies.

Alex-Laparra commented 3 years ago

see? it will work just delete all your cookies then. go to this website about:preferences#privacy then go to the manage data... and then search for tiktok and then click on remove all shown and then save changes and then once again click on remove. also dont close the tiktok music link when you are deleting your cookies.

Still doesn't work on my end sorry. I will try a few times again but I still don't get the captcha. Maybe it has something to do with the new European Laws about cookies and stuff. What country are you from? Cause I'm from France

kpopdev commented 3 years ago

middle eat but my vpn is from germany haha.

kpopdev commented 3 years ago

i will add you on discord and when you need verifyfp u can dm me i will give you always. we should wait till david fix this.

Alex-Laparra commented 3 years ago

i will add you on discord and when you need verifyfp u can dm me i will give you always. we should wait till david fix this.

Thank you!

lafritte57 commented 3 years ago

@Alex-Laparra this will fix all captcha errors https://youtu.be/MgjorCvPzxg just watch it. im using firefox btw but i think on other Web browsers works too.

Hey! Thanks a lot for this workaround and for taking the time to make a how-to video.

However, as for @Alex-Laparra, I never get the captcha window despite all my attempts and after following your tutorial and advice to the letter (deleting cookies via Dev Tools and via about:preferences). I have tried on different browsers (chrome, firefox, brave, opera) but the same result, even in private browsing.

On the other hand, the verifyFp that you communicated works perfectly!

What is strange (and maybe a clue) is that I am also in France.

EDIT:

Okay you know what, I've moved on! I noticed that when I deleted the tiktok cookies via Dev Tools, they didn't seem to be truly deleted because they still appear in the main window (which might confirm your hint of remaining cookies if we don't see the captcha page afterwards).

In doubt, I redid the same operation but connected via VPN in Germany (to reproduce your scheme)... And magic, the cookies are correctly deleted and disappear from the main window! Then, when I click on another music, I arrive well on the captcha page (with the puzzle, as on your video) allowing me to obtain a functional verifyFP!

So as Alex suggests, could it be that in France (more specifically, since in Germany I don't have the problem) the cookie management is different? Or that TikTok is able to "reassign" them according to our public IP (which in my case is fixed)?

In any case: your workaround + a VPN in Germany (and maybe elsewhere) allows me to have a working verifyFP!

Thanks a lot !

felixwann commented 3 years ago

@Alex-Laparra this will fix all captcha errors https://youtu.be/MgjorCvPzxg just watch it. im using firefox btw but i think on other Web browsers works too.

First of all thank you very much! Your tutorials really helped me, at least today my boss won't give me a hard time!

davidteather commented 3 years ago

Okay I'm going to close this issue because of changed made in V4.0.0 only things that I can really suggest are

getsec commented 3 years ago

lmfao . Imagine asking the maintainer to bypass captchas for you...

gilmarGNJ commented 3 years ago

@Alex-Laparra this will fix all captcha errors https://youtu.be/MgjorCvPzxg just watch it. im using firefox btw but i think on other Web browsers works too.

Thank you so much!!!

UzhFAN commented 2 years ago

@mina9999 thank you so much for your tutorial! Unfortunately, I face exactly the same problem as Alex. It never shows me a captcha. Can I ask you for a favor, could you maybe generate a verifyfp? I would appreciate it very much!