Open suraj-bhati opened 1 year ago
**`import asyncio import os from TikTokApi import TikTokApi
async def fetch_trending_videos(): async with TikTokApi() as api:
ms_token = "Mp6Hs8_h3-Hx3wQe7fdCsDtpjcnS5PzqGRHoupINjcXZqW_KaV-qDOHKXflqPMpwJ6j-wrIG2Z2hSLHIjS1l8KSJXKxnin58hVTiFlEpGSm61T_wEEKtwwCjFt2NHlNC9Qct0lCb42dWPzU="
# Create sessions with the ms_token
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
# Initialize the counter
counter = 0
# Get trending videos
async for video in api.trending.videos(count=100):
counter += 1 # Increment the counter
print(f"Video {counter} URL: https://www.tiktok.com/@{video.author.username}/video/{video.id}")
print(f"Total number of URLs scraped: {counter}")
if name == "main": asyncio.run(fetch_trending_videos())
`**
It looks like you're encountering an error related to the Tiktok Audio extractor API in your Python script. The error message indicates that there's an issue with the TikTokException.init() method, specifically that it's missing two required positional arguments: 'raw_response' and 'message'.
Check the TikTok API Documentation: Ensure that you are using the correct methods and parameters according to the latest version of the TikTok API. API libraries may change, and it's possible that there have been updates since you initially wrote or obtained your code.
Update TikTok API Library:
If you're using a third-party TikTok API library, make sure it's up-to-date. You can usually update it using the package manager (e.g., pip). For example:
pip install --upgrade TikTokApi
Review Your Code:
Double-check your code to ensure that you are correctly handling exceptions and that you are using the API in a way that aligns with the library's documentation.
Here's a basic example of how you might structure your code to catch and handle exceptions: `from TikTokApi import TikTokApi, TikTokException
async def fetch_trending_videos(): api = TikTokApi() try: async for video in api.trending.videos(count=100):
print(video)
except TikTokException as e:
print(f"Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
asyncio.run(fetch_trending_videos())` Make sure your code is compatible with the current version of the library.
➜ code pipython3 URL_scarper.py Traceback (most recent call last): File "/home/damner/code/URL_scarper.py", line 24, in
asyncio.run(fetch_trending_videos())
File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/damner/code/URL_scarper.py", line 17, in fetch_trending_videos
async for video in api.trending.videos(count=100):
File "/usr/local/lib/python3.10/dist-packages/TikTokApi/api/trending.py", line 43, in videos
resp = await Trending.parent.make_request(
File "/usr/local/lib/python3.10/dist-packages/TikTokApi/tiktok.py", line 429, in make_request
raise EmptyResponseException()
TypeError: TikTokException.init() missing 2 required positional arguments: 'raw_response' and 'message'
➜ code