Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] - Your Error Here #1137

Open
pulakmehta opened this issue Apr 4, 2024 · 2 comments
Open

[BUG] - Your Error Here #1137

pulakmehta opened this issue Apr 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@pulakmehta
Copy link

pulakmehta commented Apr 4, 2024

Getting the following error -

RuntimeError: asyncio.run() cannot be called from a running event loop

Code -

from TikTokApi import TikTokApi
import asyncio
import os

ms_token = os.environ.get("ms_token", None) # get your own ms_token from your cookies on tiktok.com

async def trending_videos():
async with TikTokApi() as api:
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3)
async for video in api.trending.videos(count=30):
print(video)
print(video.as_dict)

if name == "main":
asyncio.run(trending_videos())

@pulakmehta pulakmehta added the bug Something isn't working label Apr 4, 2024
@mikasiddiqui
Copy link

mikasiddiqui commented Apr 21, 2024

That's because you're most likely using it within a jupyter notebook - try adding this to the start of your code:

import nest_asyncio
nest_asyncio.apply()

Make sure to pip install it before importing

@mtworth
Copy link

mtworth commented May 27, 2024

This worked for me, thanks @mikasiddiqui .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants