davidteather / TikTok-Api

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

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

Closed davidteather closed 3 years ago

davidteather commented 4 years ago

This is a known bug and I am working to resolve it.

The package works it just spits out a ton of unwanted text.

Problematic code in browser.py

fut.result() # so the async part running the functions
issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.95. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

duplicate-issues[bot] commented 4 years ago

Hey @davidteather,

We did a quick check and this issue looks very darn similar to

This could be a coincidence, but if any of these issues solves your problem then I did a good job :smile:

If not, the maintainers will get to this issue shortly.

Cheers, Your Friendly Neighborhood ProBot

davidteather commented 4 years ago

Ok I'll end up reverting back to the old code by default, but if you need the current solution even with the weird error throwing that doesn't affect anything you can do the following.

from TikTokApi import TikTokApi
from TikTokApi.browser import set_async

set_async()
api = TikTokApi()

Then you can use the api as normal

lekhanhtoan37 commented 4 years ago

Dear @davidteather, After following your instructions. Im still getting stuck in this bug:

Traceback (most recent call last):
File "/root/TiktokFlaskService/venv/lib/python3.8/site-packages/pyppeteer/launche
self._loop.run_until_complete(self.killChrome())
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 592, in run_until_co
self._check_running()
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 552, in _check_runni
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

Im use your framework as service in server. It's ok when a few request. But this bug will happen verry soon. Im using Flask and Gunicorn to deploy. Thanks

davidteather commented 4 years ago

You don’t need to use this workaround for flask

lekhanhtoan37 commented 4 years ago

Dear @davidteather. But in my case, client-side is calling your framework (mobile app), so my solution is putting your framework work together Flask to return response for client-side. Please tell me how to fix this case. Thank you very much!

davidteather commented 4 years ago

Can you provide code for how your flask application is setup

lekhanhtoan37 commented 4 years ago

Dear @davidteather , Thank you for your helping, it was my fault. I solved it by reinstall all framework. Have a good day!

vincehxb commented 4 years ago

hi, thx for the excellent work. but following your instructions still cant fix the bug, any thought?

davidteather commented 3 years ago

Hi, I've made substantial changes in the last few days which should help with using this API in production. Open a new issue if you have any further issues.