[英]Error AttributeError: module 'aiohttp' has no attribute 'ClientSession'
Error AttributeError: module 'aiohttp' has no attribute 'ClientSession', But ClientSession exists in module, idk how to solve it. Error AttributeError: module 'aiohttp' has no attribute 'ClientSession', 但是ClientSession存在于模块中,不知道如何解决。 i tried everthing someone help我尝试了有人帮助的一切
import aiohttp
import asyncio
import json
import time
async def get_page (session,url):
async with session.get(url) as r:
return await r.text()
async def get_all(session,urls) :
tasks = []
for url in urls:
task = asyncio.create_task(get_page(session,url) )
tasks.append(task)
results = await asyncio.gather(*tasks)
return results
async def main (urls) :
async with aiohttp.ClientSession() as session : # Error here
data = await get_all(session,urls)
return data
def parse(results):
for html in results:
data = json.loads(html)
return
if __name__ == '__main__':
urls = ['https://www.google.com']
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
results = asyncio.run(main(urls))
parse(results)
The problem is you've named the script aiohttp.py
which interferes with python's ability to use the aiohttp module.问题是您将脚本命名为aiohttp.py
,这会干扰 python 使用 aiohttp 模块的能力。
Rename that file to aiohttp_custom.py
(or something else) and your problem should be gone.将该文件重命名为aiohttp_custom.py
(或其他名称),您的问题应该会消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.