TikTok-Api
TikTok-Api copied to clipboard
This event loop is already running
Hi there, I am using the last version of the api. And using this example:
from TikTokApi import TikTokApi
with TikTokApi() as api: for video in api.trending.videos(): print(video.id)
But I got this error:
RuntimeError: This event loop is already running
Task exception was never retrieved future: <Task finished name='Task-2' coro=<Connection.run() done, defined at C:\Users\idilk\anaconda3\lib\site-packages\playwright_impl_connection.py:174> exception=NotImplementedError()> Traceback (most recent call last): File "C:\Users\idilk\anaconda3\lib\site-packages\playwright_impl_connection.py", line 181, in run await self._transport.connect() File "C:\Users\idilk\anaconda3\lib\site-packages\playwright_impl_transport.py", line 132, in connect raise exc File "C:\Users\idilk\anaconda3\lib\site-packages\playwright_impl_transport.py", line 120, in connect self._proc = await asyncio.create_subprocess_exec( File "C:\Users\idilk\anaconda3\lib\asyncio\subprocess.py", line 236, in create_subprocess_exec transport, protocol = await loop.subprocess_exec( File "C:\Users\idilk\anaconda3\lib\asyncio\base_events.py", line 1630, in subprocess_exec transport = await self._make_subprocess_transport( File "C:\Users\idilk\anaconda3\lib\asyncio\base_events.py", line 491, in _make_subprocess_transport raise NotImplementedError NotImplementedError
I added this code but I am still getting the same error:
import asyncio from playwright.async_api import async_playwright
The library uses the sync api of playright at the moment, which rightfully raises an exception when you use it within a loop which Jupyter is. I hope to PR an async version of the library soon.
for now you can use https://github.com/erdewit/nest_asyncio to get it working while debugging. Do not use this outside of testing.
@monty-dev hi, I actually checked this one as well but I am getting the same error. Can you give a usage example that you tried?
Is there anyone can help? I am using python 3.9, spyder idle 5.1.5 and windows 10. I tried to use nest_asynico but this time I got this error:
[SpyderKernelApp] ERROR | Exception in message handler: Traceback (most recent call last): File "C:\Users\idilk\Anaconda3\lib\site-packages\spyder_kernels\comms\frontendcomm.py", line 164, in poll_one asyncio.run(handler(out_stream, ident, msg)) File "C:\Users\idilk\Anaconda3\lib\site-packages\nest_asyncio.py", line 32, in run return loop.run_until_complete(future) File "C:\Users\idilk\Anaconda3\lib\site-packages\nest_asyncio.py", line 60, in run_until_complete f = asyncio.ensure_future(future, loop=self) File "C:\Users\idilk\Anaconda3\lib\asyncio\tasks.py", line 680, in ensure_future raise TypeError('An asyncio.Future, a coroutine or an awaitable is ' TypeError: An asyncio.Future, a coroutine or an awaitable is required [SpyderKernelApp] ERROR | Exception in message handler: Traceback (most recent call last): File "C:\Users\idilk\Anaconda3\lib\site-packages\spyder_kernels\comms\frontendcomm.py", line 164, in poll_one asyncio.run(handler(out_stream, ident, msg)) File "C:\Users\idilk\Anaconda3\lib\site-packages\nest_asyncio.py", line 32, in run return loop.run_until_complete(future) File "C:\Users\idilk\Anaconda3\lib\site-packages\nest_asyncio.py", line 60, in run_until_complete f = asyncio.ensure_future(future, loop=self) File "C:\Users\idilk\Anaconda3\lib\asyncio\tasks.py", line 680, in ensure_future raise TypeError('An asyncio.Future, a coroutine or an awaitable is ' TypeError: An asyncio.Future, a coroutine or an awaitable is required
I'm also getting this error
v6 async