twintproject / twint

An advanced Twitter scraping & OSINT tool written in Python that doesn't use Twitter's API, allowing you to scrape a user's followers, following, Tweets and more while evading most API limitations.
MIT License
15.66k stars 2.72k forks source link

RuntimeError: This event loop is already running #1242

Open nitesh585 opened 3 years ago

nitesh585 commented 3 years ago

I have installed twint using pip install twint and trying to run simple program to scrape tweets.

c = twint.Config()
c.Search = "advertisement"
c.Min_likes = 5

twint.run.Search(c)

and got an error in colab.

RuntimeError                              Traceback (most recent call last)

<ipython-input-4-f28f8e9aab1e> in <module>()
----> 1 twint.run.Search(c)

3 frames

/usr/local/lib/python3.7/dist-packages/twint/run.py in Search(config, callback)
    325     config.Profile = False
    326     config.Profile_full = False
--> 327     run(config, callback)
    328     if config.Pandas_au:
    329         storage.panda._autoget("tweet")

/usr/local/lib/python3.7/dist-packages/twint/run.py in run(config, callback)
    224         raise
    225 
--> 226     get_event_loop().run_until_complete(Twint(config).main(callback))
    227 
    228 def Favorites(config):

/usr/lib/python3.7/asyncio/base_events.py in run_until_complete(self, future)
    561         """
    562         self._check_closed()
--> 563         self._check_runnung()
    564 
    565         new_task = not futures.isfuture(future)

/usr/lib/python3.7/asyncio/base_events.py in _check_runnung(self)
    521     def _check_runnung(self):
    522         if self.is_running():
--> 523             raise RuntimeError('This event loop is already running')
    524         if events._get_running_loop() is not None:
    525             raise RuntimeError(

RuntimeError: This event loop is already running
brenorb commented 3 years ago

try using this before your code. Worked for me.

import nest_asyncio
nest_asyncio.apply()
RichaMax commented 3 years ago

It seems that the pypi version of twint is broken see #786 (comment)

Best solution would be to do the following steps:

After this your code should be working (tested locally and it worked)

aabirouch-pi commented 3 years ago

Try this, it worked for me:

pip install nest_asyncio import nest_asyncio nest_asyncio.apply()

AdrienMau commented 2 years ago

Nest asyncio worked for me, thanks !