Fix Python – Python: Importing urllib.quote


Asked By – imrek

I would like to use urllib.quote(). But python (python3) is not finding the module.
Suppose, I have this line of code:

print(urllib.quote("châteu", safe=''))

How do I import urllib.quote?

import urllib or
import urllib.quote both give

AttributeError: 'module' object has no attribute 'quote'

What confuses me is that urllib.request is accessible via import urllib.request

Now we will see solution for issue: Python: Importing urllib.quote


In Python 3.x, you need to import urllib.parse.quote:

>>> import urllib.parse
>>> urllib.parse.quote("châteu", safe='')

According to Python 2.x urllib module documentation:


The urllib module has been split into parts and renamed in Python 3 to
urllib.request, urllib.parse, and urllib.error.

This question is answered By – falsetru

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0