davidteather / TikTok-Api

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

[BUG] - by_sound() continuously returning EmptyResponseError #789

Closed sipka closed 2 years ago

sipka commented 2 years ago

Describe the bug

I am trying to get tiktoks by sound using api.by_sound() method, but keep getting TikTokApi.exceptions.EmptyResponseError: Empty response from Tiktok. I have been on-and-off able to do it in the past few days, but after scraping video metadata for about 300 sounds, it tends to get stuck and just return the error anyway.

I am using custom_verifyFp and use_test_endpoints=True. In addition, I have used various VPNs, resolved captcha, deleted cookies, etc. I have confirmed that the sound in question exists, and have tried many different sounds to confirm the issue persists.

The buggy code

api = TikTokApi.get_instance(custom_verifyFp = my_fp, use_test_endpoints=True)

videos_by_sound = api.by_sound('7004098435989162758', count=2000, custom_did=str(random.randint(10000, 999999999)), custom_verifyFp = my_fp, use_test_endpoints=True)

Expected behavior

Returned JSON with tiktoks.

Error Trace (if any)

Put the error trace below if there's any error thrown.

Traceback (most recent call last):
  File "scrape_sound.py", line 106, in <module>
    videos_by_sound = api.by_sound(hashtag, count=n_videos, custom_did=str(random.randint(10000, 999999999)), custom_verifyFp = my_fp, use_test_endpoints=True)
  File "/Users/iamauser/opt/anaconda3/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 932, in by_sound
    res = self.get_data(url=api_url, send_tt_params=True, **kwargs)
  File "/Users/iamauser/opt/anaconda3/lib/python3.8/site-packages/TikTokApi/tiktok.py", line 375, in get_data
    raise EmptyResponseError(
TikTokApi.exceptions.EmptyResponseError: Empty response from Tiktok to https://t.tiktok.com/api/music/item_list/?aid=1988&app_name=tiktok_web&device_platform=web_mobile&region=GB&priority_region=&os=ios&referer=&root_referer=&cookie_enabled=true&screen_width=356&screen_height=1777&browser_language=en-gb&browser_platform=iPhone&browser_name=Mozilla&browser_version=Mozilla%252F5.0%2B%28iPhone%253B%2BCPU%2BiPhone%2BOS%2B12_2%2Blike%2BMac%2BOS%2BX%29%2BAppleWebKit%252F605.1.15%2B%28KHTML%2C%2Blike%2BGecko%29%2BVersion%252F15.0%2BMobile%252F15E148%2BSafari%252F604.1&browser_online=true&timezone_name=Europe%252FZurich&is_page_visible=true&focus_state=true&is_fullscreen=false&history_len=15&language=en&secUid=&musicID=7004098435989162758&count=35&cursor=0&shareUid=&language=en&verifyFp=verify_871064a669b68f5896d2267831f8140e&device_id=0959055318643727382&_signature=_02B4Z6wo00f010qd1bAAAIBCKihVYrXZBCNKnNEAALOK65

Desktop (please complete the following information):

Additional context Scraping by hashtag is working just fine, indicating that I am not necessarily banned by Tiktok.

davidteather commented 2 years ago

Please try using V5.0.0 this may solve your problem