How about urlparse.urljoin instead?