python异步编程 报错:module 'asyncio' has no attribute 'coroutine'

调试代码如下:

# -*- coding:utf-8 -*-
import asyncio

@asyncio.coroutine
def wget(host):
    print('wget %s...' % host)
    content = asyncio.open_connection(host, 80)
    reader, writer = yield from connect
    header = 'GET / HTTP/1.0\r\nHost: %s\r\n\r\n' % host
    writer.write(header.encode('utf-8'))

    yield from writer.drain()
    while True:
        line = yield from reader.readline()
        if line == b'\r\n':
            break
        print('%s header > %s' % (host, line.decode('utf-8'.rstrip())))

    writer.close()

loop = asyncio.get_event_loop()
tasks = [wget(host) for host in ['www.sina.com', 'www.shu.com', 'www.163.com']]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()

提示报错:

Traceback (most recent call last):
  File "asyncio.py", line 2, in <module>
    import asyncio
  File "/application/study/python/python3/asyncio.py", line 4, in <module>
    @asyncio.coroutine
AttributeError: module 'asyncio' has no attribute 'coroutine'

自己明明安装了asyncio库,还会报这个错,后来发现自己的文件名跟库名重复了,加载了当前的文件,所以就没有使用官方的库。那就改一下文件名就可以解决了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值