首页 新闻 会员 周边 捐助

Python 导包错误,不知是哪里错误

0
悬赏园豆:50 [已关闭问题] 关闭于 2019-07-12 17:46

源码如下, 总是运行不了报错
<code type='Python'>
import aiohttp
import asyncio

async def main(pool): # aiohttp必须放在异步函数中使用
tasks = []
sem = asyncio.Semaphore(pool) # 限制同时请求的数量
[tasks.append(control_sem(sem, 'https://api.github.com/events?a={}'.format(i))) for i in range(10)] # 十次请求
await asyncio.wait(tasks)

async def control_sem(sem, url): # 限制信号量
async with sem:
await fetch(url)

async def fetch(url):
async with aiohttp.request('GET', url) as resp:
json = await resp.json()
print(json)

loop = asyncio.get_event_loop()
loop.run_until_complete(main(pool=2))
</code>

报错信息如下

Traceback (most recent call last):
File "C:/Users/Administrator/.PyCharmCE2019.1/config/scratches/Demo3.py", line 298, in <module>
import aiohttp
File "D:\Program Files\Python3.7.2\lib\site-packages\aiohttp__init__.py", line 6, in <module>
from .client import (
File "D:\Program Files\Python3.7.2\lib\site-packages\aiohttp\client.py", line 32, in <module>
from . import hdrs, http, payload
File "D:\Program Files\Python3.7.2\lib\site-packages\aiohttp\http.py", line 7, in <module>
from .http_parser import (
File "D:\Program Files\Python3.7.2\lib\site-packages\aiohttp\http_parser.py", line 14, in <module>
from .base_protocol import BaseProtocol
File "D:\Program Files\Python3.7.2\lib\site-packages\aiohttp\base_protocol.py", line 4, in <module>
from .tcp_helpers import tcp_nodelay
File "D:\Program Files\Python3.7.2\lib\site-packages\aiohttp\tcp_helpers.py", line 20, in <module>
def tcp_keepalive(transport: asyncio.Transport) -> None:
AttributeError: module 'asyncio' has no attribute 'Transport'

EasyJS Framework的主页 EasyJS Framework | 初学一级 | 园豆:156
提问于:2019-07-12 17:39
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册