Fix urllib code to be compatible with python3