There's tons of discussion on this topic on the web. Lots of references saying "you must sanitize urls".
Even Jeff Atwood has an answer for the topic: Best way to handle security and avoid XSS with user entered URLs This answer must be disregarded because there are comments pointing out that it is wrong, but no response to those comments - so this is not a duplicate question.
But nowhere can I find a straight answer to the question "how, specifically, do I sanitize a URL in Python?", with an example.