Detailed Explanation of Usage of urlencode and urldecode in Python3

  • 2021-07-26 08:13:48
  • OfStack

In Python3, Chinese is encoded by urlencode using functions


urllib.parse.quote(string, safe='/', encoding=None, errors=None)

To convert the encoded string into Chinese, use the


urllib.parse.unquote(string, encoding='utf-8', errors='replace') 

The sample code is as follows:


test = " WeChat Public Account Bit Quantization "
print(test)
new = urllib.parse.quote(test)
print(new)
print(urllib.parse.unquote(new))

The implementation results are as follows


C:\Users\btcquant>python E:\bitcoin\wxapi.py
 WeChat Public Account Bit Quantization 
%E5%BE%AE%E4%BF%A1%E5%85%AC%E4%BC%97%E8%B4%A6%E5%8F%B7%E6%AF%94%E7%89%B9%E9%87%8F%E5%8C%96
 WeChat Public Account Bit Quantization 

Related articles: