FAQ
Hi,


Python 3.2.3 (default, Jun 18 2015, 21:46:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import urllib
urllib.request.urlopen('http://example.org')
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'request'


Same error with Python 3.4.0

Search Discussions

  • Chris Angelico at Sep 4, 2015 at 2:08 am

    On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre wrote:
    Python 3.2.3 (default, Jun 18 2015, 21:46:42)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import urllib
    urllib.request.urlopen('http://example.org')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'request'

    Same error with Python 3.4.0

    With packages, like this, you sometimes need to explicitly import the
    piece you want. That way, the urllib module doesn't have to load
    everything up just because you wanted one small part. Try this
    instead:


    import urllib.request
    urllib.request.urlopen('http://example.org')


    Hope that helps!


    ChrisA
  • Vincent Vande Vyvre at Sep 4, 2015 at 2:17 am

    Le 04/09/2015 04:08, Chris Angelico a ?crit :
    On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre
    wrote:
    Python 3.2.3 (default, Jun 18 2015, 21:46:42)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import urllib
    urllib.request.urlopen('http://example.org')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'request'

    Same error with Python 3.4.0
    With packages, like this, you sometimes need to explicitly import the
    piece you want. That way, the urllib module doesn't have to load
    everything up just because you wanted one small part. Try this
    instead:

    import urllib.request
    urllib.request.urlopen('http://example.org')

    Hope that helps!

    ChrisA
    Thanks, that works with 3.4.0. No with 3.2.3




    Vincent
  • Chris Angelico at Sep 4, 2015 at 2:30 am

    On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre wrote:
    import urllib.request
    urllib.request.urlopen('http://example.org')
    Thanks, that works with 3.4.0. No with 3.2.3

    Hmm, not sure why it wouldn't. According to the docs [1] it should be
    available. But I don't have a 3.2 anywhere around me now, so I can't
    check. (Steven D'Aprano no doubt can!) What happens when you try?
    ImportError? AttributeError?


    ChrisA


    [1] https://docs.python.org/3.2/library/urllib.request.html
  • Vincent Vande Vyvre at Sep 4, 2015 at 2:49 am

    Le 04/09/2015 04:30, Chris Angelico a ?crit :
    On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre
    wrote:
    import urllib.request
    urllib.request.urlopen('http://example.org')
    Thanks, that works with 3.4.0. No with 3.2.3
    Hmm, not sure why it wouldn't. According to the docs [1] it should be
    available. But I don't have a 3.2 anywhere around me now, so I can't
    check. (Steven D'Aprano no doubt can!) What happens when you try?
    ImportError? AttributeError?

    ChrisA

    [1] https://docs.python.org/3.2/library/urllib.request.html
    Sorry, my fault, a typo in the import line.


    Vincent
  • Mark Lawrence at Sep 4, 2015 at 3:19 am

    On 04/09/2015 03:30, Chris Angelico wrote:
    On Fri, Sep 4, 2015 at 12:17 PM, Vincent Vande Vyvre
    wrote:
    import urllib.request
    urllib.request.urlopen('http://example.org')
    Thanks, that works with 3.4.0. No with 3.2.3
    Hmm, not sure why it wouldn't. According to the docs [1] it should be
    available. But I don't have a 3.2 anywhere around me now, so I can't
    check. (Steven D'Aprano no doubt can!) What happens when you try?
    ImportError? AttributeError?

    ChrisA

    [1] https://docs.python.org/3.2/library/urllib.request.html

    If my understanding is correct, owing to the way the time machine works,
    Steven still has Python versions -3.6 to -0.1 running.


    --
    My fellow Pythonistas, ask not what our language can do for you, ask
    what you can do for our language.


    Mark Lawrence
  • MRAB at Sep 4, 2015 at 2:41 am

    On 2015-09-04 03:17, Vincent Vande Vyvre wrote:
    Le 04/09/2015 04:08, Chris Angelico a ?crit :
    On Fri, Sep 4, 2015 at 11:56 AM, Vincent Vande Vyvre
    wrote:
    Python 3.2.3 (default, Jun 18 2015, 21:46:42)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import urllib
    urllib.request.urlopen('http://example.org')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'request'

    Same error with Python 3.4.0
    With packages, like this, you sometimes need to explicitly import the
    piece you want. That way, the urllib module doesn't have to load
    everything up just because you wanted one small part. Try this
    instead:

    import urllib.request
    urllib.request.urlopen('http://example.org')

    Hope that helps!

    ChrisA
    Thanks, that works with 3.4.0. No with 3.2.3
    It works for me with Python 3.2.5 on Windows.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 4, '15 at 1:56a
activeSep 4, '15 at 3:19a
posts7
users4
websitepython.org

People

Translate

site design / logo © 2019 Grokbase