Fixing ImportError: cannot import name 'urlencode' in Python3
Problem:
Your python 3.x interpreter prints the error message
importerror.txt
ImportError: cannot import name 'urlencode'Solution
As described by Fred Foo here on StackOverflow, Python3 contains urlencode() not in the urllib module but in urllib.parse.
Therefore you have to change
fix_urlencode.py
from urllib import urlencodeto
fix_compat_urlencode.py
from urllib.parse import urlencodeIf you intend to write code for both Python2 and Python3, prefer using:
fix_compat_tryexcept.py
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencodeCheck out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow