Fix urllib imports to work with both python 2 and 3
Fix string type checking to work in both python 2 and 3