A slight improvement on @would's answer will include safe characters in the method call. By default, urllib2.quote () only includes / _ - . as a safe character, which means that characters such as : will be converted, making the URL unnecessary.
For example:
url = https://www.zomato.com/pittsburgh/caffè-damore-catering-pittsburgh print urllib2.quote(url.encode('utf-8')) >>> https%3A//www.zomato.com/pittsburgh/caff%C3%A8-damore-catering-pittsburgh print urllib2.quote(url.encode('utf-8'),':/') >>> https:////www.zomato.com/pittsburgh/caff%C3%A8-damore-catering-pittsburgh
Note the slight difference in the outputs in the https portion of the URL.
Hope this saves someone else when I need to find out!
Austin a
source share