简体   繁体   English

错误 AttributeError:模块 'aiohttp' 没有属性 'ClientSession'

[英]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.

相关问题 AttributeError:'模块'对象没有属性'Popen'错误 - AttributeError: 'module' object has no attribute 'Popen' error Python错误:AttributeError:'module'对象没有属性 - Python error: AttributeError: 'module' object has no attribute AttributeError:模块“miceforest”没有属性“MultipleImputedKernel”错误 - AttributeError: module 'miceforest' has no attribute 'MultipleImputedKernel' error 错误 - AttributeError:模块“keras”没有属性“sum” - Error - AttributeError: module 'keras' has no attribute 'sum' 错误:AttributeError:模块“ pygame”没有属性“颜色” - Error: AttributeError: module 'pygame' has no attribute 'Colors' 属性错误:模块“tensorflow”没有属性“变量”“错误” - AttributeError: module 'tensorflow' has no attribute 'Variable' “ERROR” AttributeError:模块“tensorflow”没有属性“app”:错误 - AttributeError: module 'tensorflow' has no attribute 'app': error AttributeError: 'module' 对象没有属性 'error' - AttributeError: 'module' object has no attribute 'error' 错误:AttributeError:模块“numpy”没有属性“sqrt” - Error: AttributeError: module 'numpy' has no attribute 'sqrt' AttributeError:模块没有属性 - AttributeError: module has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM