TikTok-Api icon indicating copy to clipboard operation
TikTok-Api copied to clipboard

[BUG] - RuntimeError: This event loop is already running

Open ekmckinley opened this issue 2 years ago • 3 comments

Fill Out the template :)

Describe the bug

I believe have installed all required library and still getting runtime error. When I run the code (pasted below), it gives me "This event loop is already running"

The buggy code

!pip install TikTokApi import pandas as pd

from TikTokApi import TikTokApi api = TikTokApi() n_videos = 100 username = 'washingtonpost' user_videos = api.byUsername(username, count=n_videos)

Error Trace (if any)

RuntimeError: This event loop is already running


Desktop (please complete the following information):

  • OS: macOS Monterey 12.3.1

Additional context

Add any other context about the problem here.

ekmckinley avatar May 05 '22 17:05 ekmckinley

I get the same error in Google Colab

` try: import TikTokApi except: from pip._internal.main import main as pip pip(["install", "TikTokApi"]) import TikTokApi

!python -m playwright install

with TikTokApi() as api: tag = api.hashtag(name="funny")

print(tag.info())

for video in tag.videos():
    print(video.id)

`

questmapping avatar May 13 '22 10:05 questmapping

Same problem in a Jupyter notebook.

from TikTokApi import TikTokApi

from TikTokApi import TikTokApi

api = TikTokApi()

for trending_video in api.trending.videos(count=50):
    # Prints the author's username of the trending video.
    print(trending_video.author.username)

Outputs

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [2], in <cell line: 3>()
      1 from TikTokApi import TikTokApi
----> 3 api = TikTokApi()
      5 for trending_video in api.trending.videos(count=50):
      6     # Prints the author's username of the trending video.
      7     print(trending_video.author.username)

File ~/opt/anaconda3/lib/python3.9/site-packages/TikTokApi/tiktok.py:119, in TikTokApi.__init__(self, logging_level, request_delay, custom_device_id, generate_static_device_id, custom_verify_fp, use_test_endpoints, proxy, executable_path, *args, **kwargs)
    116 self.logger.setLevel(logging_level)
    118 with _thread_lock:
--> 119     self._initialize(
    120         request_delay=request_delay,
    121         custom_device_id=custom_device_id,
    122         generate_static_device_id=generate_static_device_id,
    123         custom_verify_fp=custom_verify_fp,
    124         use_test_endpoints=use_test_endpoints,
    125         proxy=proxy,
    126         executable_path=executable_path,
    127         *args,
    128         **kwargs,
    129     )

File ~/opt/anaconda3/lib/python3.9/site-packages/TikTokApi/tiktok.py:163, in TikTokApi._initialize(self, **kwargs)
    158     self._custom_device_id = "".join(
    159         random.choice(string.digits) for num in range(19)
    160     )
    162 if self._signer_url is None:
--> 163     self._browser = asyncio.get_event_loop().run_until_complete(
    164         asyncio.gather(browser.create(**kwargs))
    165     )[0]
    167     self._user_agent = self._browser.user_agent
    169 try:

File ~/opt/anaconda3/lib/python3.9/asyncio/base_events.py:623, in BaseEventLoop.run_until_complete(self, future)
    612 """Run until the Future is done.
    613 
    614 If the argument is a coroutine, it is wrapped in a Task.
   (...)
    620 Return the Future's result, or raise its exception.
    621 """
    622 self._check_closed()
--> 623 self._check_running()
    625 new_task = not futures.isfuture(future)
    626 future = tasks.ensure_future(future, loop=self)

File ~/opt/anaconda3/lib/python3.9/asyncio/base_events.py:583, in BaseEventLoop._check_running(self)
    581 def _check_running(self):
    582     if self.is_running():
--> 583         raise RuntimeError('This event loop is already running')
    584     if events._get_running_loop() is not None:
    585         raise RuntimeError(
    586             'Cannot run the event loop while another loop is running')

RuntimeError: This event loop is already running

liechtym avatar Jun 17 '22 18:06 liechtym

Just experienced this error as well.

It seems just initializing the class triggers the error. Weird.

s2t2 avatar Aug 05 '22 01:08 s2t2

Same error here!

RazeBerry avatar May 23 '23 19:05 RazeBerry

V6 fully async should be fine

davidteather avatar Aug 08 '23 22:08 davidteather