Aiohttp: AttributeError: module 'asyncio' has no attribute 'current_task'

Created on 16 Mar 2018  路  2Comments  路  Source: aio-libs/aiohttp

Long story short

Get mistake when I use aiohttp make a get request with aiohttp==3.0.9 but not with 3.0.5

Expected behaviour

Return the content of page

Actual behaviour

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    loop.run_until_complete(hello("http://httpbin.org/headers"))
  File "/usr/local/python3/lib/python3.7/asyncio/base_events.py", line 466, in run_until_complete
    return future.result()
  File "test.py", line 7, in hello
    async with session.get(url) as response:
  File "/usr/local/python3/lib/python3.7/site-packages/aiohttp/client.py", line 782, in __aenter__
    self._resp = await self._coro
  File "/usr/local/python3/lib/python3.7/site-packages/aiohttp/client.py", line 271, in _request
    with timer:
  File "/usr/local/python3/lib/python3.7/site-packages/aiohttp/helpers.py", line 643, in __enter__
    task = current_task(loop=self._loop)
  File "/usr/local/python3/lib/python3.7/site-packages/aiohttp/helpers.py", line 188, in current_task
    task = asyncio.current_task(loop=loop)
AttributeError: module 'asyncio' has no attribute 'current_task'

Steps to reproduce

import asyncio
from aiohttp import ClientSession

async def hello(url):
    async with ClientSession() as session:
        async with session.get(url) as response:
            response = await response.read()
            print(response)

loop = asyncio.get_event_loop()

loop.run_until_complete(hello("http://httpbin.org/headers"))

Your environment

Python:3.7.0a1
aiohttp:3.0.9
OS:CentOS7

outdated

All 2 comments

It works:

Python 3.7.0b2+ (heads/3.7:6e65e44626, Mar 16 2018, 11:07:20) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> asyncio.current_task
<function current_task at 0x7ffbd95681c8>

The function is here: https://github.com/python/cpython/blob/3.7/Lib/asyncio/tasks.py#L27-L31

I don't remember when I've added the function and what is first Python version supported this.
3.7.0 beta definitely have it, please upgrade your Python.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].

Was this page helpful?
0 / 5 - 0 ratings