AttributeError: module 'urllib' has no attribute 'urlopen' in Python

Dung Do Tien Oct 03 2021 944

Hello you guys, I am a newbie in Python and I'm also studying more about Python.

I have some lines of code,  I want to get all html from the some website to detect some data. I try code as below:

import urllib

stream = urllib.urlopen("")
content =


But I get an exception AttributeError: module 'urllib' has no attribute 'urlopen' when I run code above.

Traceback (most recent call last):
  File "", line 3, in <module>
    stream = urllib.urlopen("")
AttributeError: module 'urllib' has no attribute 'urlopen'

And I am using python 3.8.2

Anyone can explain it to me? How can I solve it?

Thanks for any suggestions.

Have 2 answer(s) found.
  • T

    Truong Thai Oct 03 2021

    Below is solution for Python 3.x

    from urllib.request import openlink
    url = ''
    file = openlink(url)
    response =

    It work well for me!

  • J

    Jair Rojas Garcia Oct 03 2021

    Your code only work for version 2.x.

    An with python 3.x you can change import urllib to import urllib.request as url. See example below:

    import urllib.request as url
    stream = url.urlopen("")
    content =

    And it worked for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close