V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
bestehen
V2EX  ›  Linux

Python 异步代码运行 为啥报错 module 'aiohttp' has no attribute 'ClientSession'

  •  
  •   bestehen · 2018-06-18 11:50:09 +08:00 · 4174 次点击
    这是一个创建于 2349 天前的主题,其中的信息可能已经有所发展或是发生改变。

    with (await sem): async with aiohttp.ClientSession() as session: async with session.get(url, headers=headers) as res: page = await res.text() if callback: callback(page, **kwarags) else: return page

    Traceback (most recent call last): File "aiohttp.py", line 57, in <module> main() File "aiohttp.py", line 48, in main loop.run_until_complete(fetch(BASE_URL+"/43_43074/", callback=parse_url)) File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete return future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result raise self._exception File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step result = coro.send(None) File "aiohttp.py", line 16, in fetch async with aiohttp.ClientSession() as session: AttributeError: module 'aiohttp' has no attribute 'ClientSession'

    2 条回复    2018-06-18 19:11:42 +08:00
    kindjeff
        1
    kindjeff  
       2018-06-18 11:53:48 +08:00
    因为你有个文件名字叫 aiohttp.py
    bestehen
        2
    bestehen  
    OP
       2018-06-18 19:11:42 +08:00
    @kindjeff 我换了个名字也一样啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2737 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 11:38 · PVG 19:38 · LAX 03:38 · JFK 06:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.