fix for urlencode error in python 3.
Py2/3 compatibility fixes.
More py2/3 compat fixes.
import order fix.
Merge pull request #462 from troygrosfield/master

More python 2/3 compatibility fixes