talkpython / async-techniques-python-course

Async Techniques and Examples in Python Course
https://training.talkpython.fm/courses/explore_async_python/async-in-python-with-threading-and-multiprocessing
MIT License
451 stars 249 forks source link

04 web_scraping asyncio.create_task don't exist #5

Closed NissesSenap closed 5 years ago

NissesSenap commented 5 years ago

Hi

Don't understand how it works for you in the demo but when i run it crases straight away. I have tried multiple times and when i try to start 04-asyncio/web_scraping/async_scrape/program.py i get the following error.

python program.py Traceback (most recent call last): File "program.py", line 58, in main() File "program.py", line 32, in main loop.run_until_complete(get_title_range()) File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete return future.result() File "program.py", line 49, in get_title_range tasks.append((n, asyncio.create_task(get_html(n)))) AttributeError: module 'asyncio' has no attribute 'create_task'

Using pipenv: aiodns==1.1.1 aiohttp==3.4.4 async-timeout==3.0.0 attrs==18.2.0 beautifulsoup4==4.6.3 bs4==0.0.1 cchardet==2.1.4 chardet==3.0.4 colorama==0.3.9 idna-ssl==1.1.0; python_version < '3.7' idna==2.7 multidict==4.4.2 pycares==2.3.0 yarl==1.2.6

python --version Python 3.6.6

mikeckennedy commented 5 years ago

What version of Python are you using?

mikeckennedy commented 5 years ago

You can call create_task on the loop object rather than on the asyncio module as well. Give that a try.

mikeckennedy commented 5 years ago

I just tried this on 3.6 and got the same error as you. But works fine under 3.7. So I updated the code to work on 3.6 too.