Python 3.5.1 urllib has no attribute request

user1999806 picture user1999806 · May 5, 2016 · Viewed 62.7k times · Source

I have tried

import urllib.request

or

import urllib

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

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

Answer

Swordsman picture Swordsman · Dec 19, 2016

According to this, you have to use the following:

import urllib.request

The reason is:

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.