vladkens / twscrape

2024! X / Twitter API scrapper with authorization support. Allows you to scrape search results, User's profiles (followers/following), Tweets (favoriters/retweeters) and more.
https://pypi.org/project/twscrape/
MIT License
946 stars 121 forks source link

RuntimeError while running example code #186

Closed Alexandros11 closed 4 months ago

Alexandros11 commented 4 months ago

I was trying to run test code 'parallel_search_with_limit.py' and I got following erroor:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[5], line 46
     42         worker_task.cancel()
     45 if __name__ == "__main__":
---> 46     asyncio.run(main())

File /usr/lib/python3.10/asyncio/runners.py:33, in run(main, debug)
      9 """Execute the coroutine and return the result.
     10 
     11 This function runs the passed coroutine, taking care of
   (...)
     30     asyncio.run(main())
     31 """
     32 if events._get_running_loop() is not None:
---> 33     raise RuntimeError(
     34         "asyncio.run() cannot be called from a running event loop")
     36 if not coroutines.iscoroutine(main):
     37     raise ValueError("a coroutine was expected, got {!r}".format(main))

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

Why this error happend? I am using python 3.10.12.

Alexandros11 commented 4 months ago

I would like to provide answer for my own question:

I used nest_asyncio to go around it. Added to the code:

import nest_asyncio
nest_asyncio.apply()