def fix_url(s, charset='utf-8'):
 if isinstance(s, unicode):
  s = s.encode(charset, 'ignore')
 (scheme, netloc, path, qs, anchor) = urlparse.urlsplit(s)
 path = urllib.quote(path, '/%')
 qs = urllib.quote_plus(qs, ':&=')
 return urlparse.urlunsplit((scheme, netloc, path, qs, anchor))

def fix_url ( s , charset = 'utf-8' ) : if isinstance ( s , unicode ) : s = s . encode ( charset , 'ignore' ) ( scheme , netloc , path , qs , anchor ) = urlparse . urlsplit ( s ) path = urllib . quote ( path , '/%' ) qs = urllib . quote_plus ( qs , ':&=' ) return urlparse . urlunsplit ( ( scheme , netloc , path , qs , anchor ) )
fix the url so it is proper formatted and encoded .