[Python] AttributeError: module 'queue' has no attribute 'SimpleQueue' [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    I follow typing the code from https://realpython.com/async-io-python/#async-ios-roots-in-generators to practice crawling with aiohttp.

    Especially when I started to code section 'A Full Program: Asynchronous Requests', I encountered an error.

    Here is my code.

    async def fetch_html(url: str, session: ClientSession, **kwargs) -> str:
    resp = await session.request(method='GET', url=url, **kwargs)
    resp.raise_for_status()
    html = await resp.text()
    return html

    async def bulk_crawl_and_write(file: IO, urls: set, **kwargs) -> None:
    urls = [
    'https://regex101.com/'
    ]
    async with ClientSession() as session:
    tasks = []
    for url in urls:
    tasks.append(fetch_html(url=url, session=session, **kwargs))
    await asyncio.gather(*tasks)

    if __name__ == '__main__':
    asyncio.run(bulk_crawl_and_write(file=None, urls=None))



    And the traceback.

    Traceback (most recent call last):
    File "areq2.py", line 108, in <module>
    asyncio.run(bulk_crawl_and_write(file=outpath, urls=urls))
    File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
    File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
    File "areq2.py", line 92, in bulk_crawl_and_write
    await asyncio.gather(*tasks)
    File "areq2.py", line 79, in write_one
    async with aiofiles.open(file, "a") as f:
    File "/Users/jun/Project/.venv_exp/lib/python3.7/site-packages/aiofiles/base.py", line 78, in __aenter__
    self._obj = yield from self._coro
    File "/Users/jun/Project/.venv_exp/lib/python3.7/site-packages/aiofiles/threadpool/__init__.py", line 35, in _open
    f = yield from loop.run_in_executor(executor, cb)
    File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 749, in run_in_executor
    executor = concurrent.futures.ThreadPoolExecutor()
    File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/thread.py", line 135, in __init__
    self._work_queue = queue.SimpleQueue()
    AttributeError: module 'queue' has no attribute 'SimpleQueue'



    I copy & pasted the whole code from the provided link to check if the rest codes are essential to run normal, but it returns the same error.

    I also checked my python version and it is 3.7.3

    Continue reading...

Compartilhe esta Página