Resolve urlencode import with tolerance for Python 3

These import statements belong at the top of the file. See https://www.python.org/dev/peps/pep-0008/#imports.