Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'asyncio' has no attribute 'current_task' #2840

Closed
focalism opened this issue Mar 16, 2018 · 2 comments
Closed

AttributeError: module 'asyncio' has no attribute 'current_task' #2840

focalism opened this issue Mar 16, 2018 · 2 comments
Labels

Comments

@focalism
Copy link

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

@asvetlov
Copy link
Member

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.

@lock
Copy link

lock bot commented Oct 28, 2019

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].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants