Fixing ImportError: cannot import name 'urlencode' in Python3

Problem:

Your python 3.x interpreter prints the error message

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

from urllib import urlencode

to

from urllib.parse import urlencode

If you intend to write code for both Python2 and Python3, prefer using:

try:
    from urllib import urlencode
except ImportError:
    from urllib.parse import urlencode