Reputation: 33
Whenever I run code which requires aiohttp, I get the error below:
Traceback (most recent call last):
File "C:\Users\HP\.atom\async8.py", line 1, in <module>
from aiohttp import web
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\__init__.py", line 6, in <module>
from .client import * # noqa
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\client.py", line 15, in <module>
from . import connector as connector_mod
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\connector.py", line 13, in <module>
from . import hdrs, helpers
File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\aiohttp\helpers.py", line 30
ensure_future = asyncio.async
^
SyntaxError: invalid syntax
Examples of codes I've tried to run from https://docs.aiohttp.org/en/stable/ include:
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.get('http://python.org') as response:
print("Status:", response.status)
print("Content-type:", response.headers['content-type'])
html = await response.text()
print("Body:", html[:15], "...")
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
and
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
if __name__ == '__main__':
web.run_app(app)
I've tried several other examples but they all produce the same error. What could be causing this?. I'm using python 3.8.6 and the latest version of aiohttp
Update: It seems the error is caused by importing aiohttp. I get the error just by typing 'import aiohttp' on cmd.
Upvotes: 1
Views: 3555
Reputation: 33
It seems that
pip install aiohttp
installs a version incompatible with my current python version. pip install aiohttp==3.5.4
solved the issue for me. Thank you @edoput for pointing that out.
Upvotes: 2