#๐Ÿ”’ this error is confusing!

4 messages ยท Page 1 of 1 (latest)

hard reef
#

i have this code:
import asyncio
import aiohttp
import feedparser

async def fetch_news(session, query):
rss_url = f'https://news.google.com/rss/search?q={query}&hl=en-US&gl=US&ceid=US:en'
async with session.get(rss_url) as response:
data = await response.text()
feed = feedparser.parse(data)
headlines = [entry.title for entry in feed.entries]
return headlines

async def scrape_topics(topics):
async with aiohttp.ClientSession() as session:
tasks = [fetch_news(session, topic) for topic in topics]
return await asyncio.gather(*tasks)

async def main():
topics = ['amazon', 'apple', 'costco'] # Example list of topics
headlines = await scrape_topics(topics)

for topic, headlines_list in zip(topics, headlines):
    print(f"Headlines for {topic}:")
    for headline in headlines_list:
        print(headline)
    print()

if name == "main":
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
finally:
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()

and when i run it, i get the top 10 headlines from the 3 asked for queries, but at thend, i get this error:
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B870205EA0>
Traceback (most recent call last):
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in del
self.close()
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B870205EA0>
Traceback (most recent call last):
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in del
self.close()
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001B870205EA0>
Traceback (most recent call last):
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in del
self.close()
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
self._check_closed()
File "C:\Users\anays\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

dreamy monolithBOT
#

@hard reef

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dreamy monolithBOT
#

@hard reef

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.