Are you looking for urllib.quote or urllib.quote_plus? Note that you do not quote the entire url string as you mentioned in the question. You normally quote the part in the path or after the query string. Whichever you are going to use in the application.