How can I create a percent encoded URL from complete URL?
问题 The input url is mixed ascii and multi byte code. And I can't change this strings. I would like to download this url, but an error occured ordinal not in range(128) . input_url = "http://sample.jp/api?v1=aaa&v2=日本語&v3=ccc" req = urllib.request.Request(input_url) resp = None try: resp = urllib.request.urlopen(req) except UnicodeEncodeError as e: print(e.reason) # I had an error `ordinal not in range(128)` return resp First, I tried urllib.parse.quote() but the result is http%3a%2f%2fsample