Python 3.5.1 urllib has no attribute request

I tried

import urllib.request 

or

 import urllib 

The path for my urllib /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/urllib/__init__.py

I am wondering where urlopen is, or is my python module pointing to the wrong file?

+14
python urllib urlopen
May 05 '16 at 4:05
source share
4 answers

Use this:

import urllib.request

The reason is this:

In such packages, it is sometimes necessary to explicitly import what you want. Thus, the urllib module does not load everything simply because you need a small part.

According to this

+28
Dec 19 '16 at 7:03
source share

In python 3.6.x, this worked for me, so I didn't have to change the code at all:

 import urllib.request as urllib 
+4
Oct 24 '18 at 7:41
source share

If none of the above help you, try renaming your Python module.

In my particular case, the problem was that the file I was running was called http.py Once I changed the name to test-http.py , importing urllib.request fixed the AttributeError: module 'urllib' has no attribute 'request' error AttributeError: module 'urllib' has no attribute 'request'

I noticed that later during the exception tracing, the inner packages tried to get a module named http , so I guessed that my module name was in the order of things ...

+1
Oct 20 '18 at 6:27
source share
 import urllib.request as urllib 

then in the code urlopen function call

example:

 test = urllib.urlopen("----") 
0
Jun 17. '19 at 20:22
source share



All Articles