Fix reference to urlencode on Python 2
Fix test failures on Python 2