You can use the six.moves for this that way you can combine it all in one line, see here for more info:

http://pythonhosted.org//six/#module-six.moves.urllib.parse