The urllib package serves as a namespace only. There are other modules under urllib like request and parse.
For optimization importing urllib doesn't import other modules under it. Because doing so would consume processor cycles and memory, but people may not need those other modules.
Individual modules under urllib must be imported separately depending on the needs.

Try these, the first one fails but the second succeeds because when flask is imported flask itself imports urllib.parse.

python3 -c 'import urllib, sys;print(sys.modules["urllib.parse"])'
python3 -c 'import flask, sys;print(sys.modules["urllib.parse"])'
Answer from Nizam Mohamed on Stack Overflow
Discussions

Rhino 9 WIP Python 3 Error: module 'urllib' has no attribute 'parse'
Hi Guys, Been trying to test DKUI in Rhino 9 WIP and get this error on PY3 components: AttributeError: module ‘urllib’ has no attribute ‘parse’ import urllib save_name = urllib2.parse.quote_plus("string with spaces that need to be URL quoted") print (save_name) It appears that urllib ... More on discourse.mcneel.com
🌐 discourse.mcneel.com
0
0
June 11, 2025
AttributeError: 'module' object has no attribute 'parse'
$ playlistfromsong -s 'deep purle child of time' Generating playlist for 3 songs from 'deep purle child of time' PLAYLIST: Deep Purple - Child In Time (Son Of Aleric - Instrumental) Traceback (most recent call last): File "/usr/local/bin... More on github.com
🌐 github.com
5
October 10, 2017
AttributeError: module 'urllib' has no attribute 'error'
I got this error: AttributeError: module 'urllib' has no attribute 'error' I think in the client.py we should import urllib.request other than import urllib, in python 3.7 and pytho... More on github.com
🌐 github.com
17
June 17, 2020
import urllib.parse fails when Python run from command line - Stack Overflow
I have a feeling that IPython resolves ... urllib.parse to avoid this error 2015-10-19T18:44:16.703Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Stack Overflow chat opening up to all users in January; Stack Exchange chat... ... 0 Module 'urllib' has no attribute 'request' ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Python Forum
python-forum.io › thread-40409.html
urllib can't find "parse"
July 23, 2023 - I don't know if it's just me having a 'senior' moment, but when I run the following code in idle import urllib print(urllib.parse.quote('my file.txt'))I get the output my file.txtbut when I run the same code from the command line I get Tracebac...
🌐
McNeel Forum
discourse.mcneel.com › rhino developer
Rhino 9 WIP Python 3 Error: module 'urllib' has no attribute 'parse' - Rhino Developer - McNeel Forum
June 11, 2025 - Hi Guys, Been trying to test DKUI ... with spaces that need to be URL quoted") print (save_name) It appears that urllib is not being imported at all....
🌐
Python
bugs.python.org › issue36701
Issue 36701: module 'urllib' has no attribute 'request' - Python tracker
April 23, 2019 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/80882
🌐
GitHub
github.com › schollz › playlistfromsong › issues › 36
AttributeError: 'module' object has no attribute 'parse' · Issue #36 · schollz/playlistfromsong
October 10, 2017 - $ playlistfromsong -s 'deep purle child of time' Generating playlist for 3 songs from 'deep purle child of time' PLAYLIST: Deep Purple - Child In Time (Son Of Aleric - Instrumental) Traceback (most recent call last): File "/usr/local/bin/playlistfromsong", line 11, in <module> sys.exit(main()) File "/usr/lib/python2.7/dist-packages/click/core.py", line 716, in __call__ return self.main(*args, **kwargs) File "/usr/lib/python2.7/dist-packages/click/core.py", line 696, in main rv = self.invoke(ctx) File "/usr/lib/python2.7/dist-packages/click/core.py", line 889, in invoke return ctx.invoke(self.c
Author   xaionaro
🌐
GitHub
github.com › druid-io › pydruid › issues › 228
AttributeError: module 'urllib' has no attribute 'error' · Issue #228 · druid-io/pydruid
June 17, 2020 - I got this error: AttributeError: module 'urllib' has no attribute 'error' I think in the client.py we should import urllib.request other than import urllib, in python 3.7 and pytho...
Author   yingbo
Find elsewhere
🌐
YouTube
youtube.com › hey delphi
PYTHON : AttributeError: module 'urllib' has no attribute 'parse' - YouTube
PYTHON : AttributeError: module 'urllib' has no attribute 'parse'To Access My Live Chat Page, On Google, Search for "hows tech developer connect"So here is a...
Published   May 13, 2023
Views   28
Top answer
1 of 2
5

When you run import urllib, it creates the module object of the urllib module (which is actually a package) without importing its submodules (parse, request etc.).

You need the parent module object (urllib) to be in your namespace if you want to access its submodule using attribute access. In addition to that, that submodule must already be loaded (imported). From the documentation:

if package spam has a submodule foo, after importing spam.foo, spam will have an attribute foo which is bound to the submodule. [...] The invariant holding is that if you have sys.modules['spam'] and sys.modules['spam.foo'] (as you would after the above import), the latter must appear as the foo attribute of the former.

There is only one instance of each module, thus any changes made to the urllib module object (stored in sys.modules['urllib']) get reflected everywhere.

You don't import urllib.parse, but IPython does. To prove this I'm going to create a startup file:

import urllib
print('Running the startup file: ', end='')
try:
    # After importing  'urllib.parse' ANYWHERE,
    # 'urllib' will have the 'parse' attribute.
    # You could also do "import sys; sys.modules['urllib'].parse"
    urllib.parse
except AttributeError:
    print("urllib.parse hasn't been imported yet")
else:
    print('urllib.parse has already been imported')
print('Exiting the startup file.')

and launch ipython

vaultah@base:~$ ipython
Running urllib/parse.py
Running the startup file: urllib.parse has already been imported
Exiting the startup file.
Python 3.6.0a0 (default:089146b8ccc6, Sep 25 2015, 14:16:56) 
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.

It is the side effect of importing pydoc during the startup of IPython (which ipython is /usr/local/bin/ipython):

/usr/local/bin/ipython, line 7:
  from IPython import start_ipython
/usr/local/lib/python3.6/site-packages/IPython/__init__.py, line 47:
  from .core.application import Application
/usr/local/lib/python3.6/site-packages/IPython/core/application.py, line 24:
  from IPython.core import release, crashhandler
/usr/local/lib/python3.6/site-packages/IPython/core/crashhandler.py, line 28:
  from IPython.core import ultratb
/usr/local/lib/python3.6/site-packages/IPython/core/ultratb.py, line 90:
  import pydoc
/usr/local/lib/python3.6/pydoc.py, line 68:
  import urllib.parse

This explains why the below code fails - you only import urllib and nothing seems to import urllib.parse:

$ python -c 'import urllib; print(urllib.parse)'

On the other hand, the following command works because datetime.datetime is not a module. It's a class that gets imported during import datetime.

$ python -c 'import datetime; print(datetime.datetime)'
2 of 2
3

urllib.parse is available from Python 3 onwards. I think you might need to import urllib.parse, not import urllib. Not sure if (when) submodule import is implicit.

I would guess IPython imports urllib.parse on startup and that is why it is available.

parse is a module not an attribute:

Python 3.4.2 (default, Oct 15 2014, 22:01:37)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> urllib.parse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'parse'
>>> import urllib.parse
>>> urllib.parse
<module 'urllib.parse' from '/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/urllib/parse.py'>
🌐
Sublime Forum
forum.sublimetext.com › t › module-error-when-running-a-plugin › 23611
Module error when running a plugin - Plugin Development - Sublime Forum
October 8, 2016 - I’m having a strange error with the URLEncode plugin, which used to work but now doesn’t. It’s making a call to urllib.parse.quote(s, safe='') which now fails with an error AttributeError: 'module' object has no attribute 'parse' and indeed, when I try to run this command in the console: import urllib; print(repr(urllib)); print(repr(urllib.parse)) it results in this error: Traceback (most recent call last): File ...
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 13465
[Web App]:urllib.parse.unquote is not a attribute : Forums : PythonAnywhere
[DEBUG] dir(urllib.parse) = ['DefragResult', 'DefragResultBytes', 'MAX_CACHE_SIZE', 'ParseResult', 'ParseResultBytes', 'Quoter', 'ResultBase', 'SplitResult', 'SplitResultBytes', '_ALWAYS_SAFE', '_ALWAYS_SAFE_BYTES', '_DefragResultBase', '_NetlocResultMixinBase', '_NetlocResultMixinBytes', '_NetlocResultMixinStr', '_ParseResultBase', '_ResultMixinBytes', '_ResultMixinStr', '_SplitResultBase', 'all', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'spec', '_asciire', '_coerce_args', '_decode_args', '_encode_result', '_hexdig', '_hextobyte', '_hostprog', '_implicit_encoding', '_
🌐
GitHub
github.com › sphinx-contrib › doxylink › issues › 5
AttributeError: 'module' object has no attribute 'parse' in 1.4 · Issue #5 · sphinx-contrib/doxylink
December 5, 2017 - [ 2%] alignment_prerejective Exception occurred: File "/home/sergio/.local/lib/python2.7/site-packages/sphinxcontrib/doxylink/doxylink.py", line 432, in find_doxygen_link if os.path.isabs(rootdir) or urllib.parse.urlparse(rootdir).scheme: AttributeError: 'module' object has no attribute 'parse' The full traceback has been saved in /tmp/sphinx-err-esXIV6.log, if you want to report the issue to the developers.
Author   SergioRAgostinho
🌐
GitHub
github.com › yamitzky › req › issues › 1
AttributeError: module 'urllib' has no attribute 'parse' · Issue #1 · yamitzky/req
August 13, 2019 - $ docker run -it -v $(pwd):/tmp ... url, params=params, **kwargs) File "/tmp/req.py", line 46, in request purl = urllib.parse.urlparse(url) AttributeError: module 'urllib' has no attribute 'parse'...
🌐
Python
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components — Python 3.14.4 ...
Deprecated since version 3.14: Accepting objects with false values (like 0 and []) except empty strings and byte-like objects and None is now deprecated. ... Working Group for the URL Standard that defines URLs, domains, IP addresses, the application/x-www-form-urlencoded format, and their API. ... This is the current standard (STD66). Any changes to urllib.parse module should conform to this.
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-57989 › Cannot-find-reference-to-urllib.parse
Cannot find reference to `urllib.parse` : PY-57989
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Google Groups
groups.google.com › g › boto-users › c › jVHch4guqSs
AttributeError: 'module' object has no attribute 'quote'
"The urllib module has been split into parts and renamed in Python 3 to urllib.request, urllib.parse, and urllib.error"
🌐
GitHub
github.com › python-gitlab › python-gitlab › issues › 271
AttributeError: module 'urllib' has no attribute 'urlencode' (Python 3, repository_blob) · Issue #271 · python-gitlab/python-gitlab
June 5, 2017 - File "[blah blah blah]/lib/python3.6/site-packages/gitlab/v3/objects.py", line 1885, in repository_blob url += '?%s' % (urllib.urlencode({'filepath': filepath})) AttributeError: module 'urllib' has no attribute 'urlencode' urlencode was moved in py3 to urllib.parse.urlencode (https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode).
Author   mdhausman