Today there is a need to pass the Chinese parameter to the URL
But the parameters of the script passing GBK in the GBK environment always give me Unicode decoding errors. It's annoying.
So we choose to use UrlEncode to deal with Chinese,
Because the domestic and foreign website code is different, the country is GBK, the foreign is UTF8.
>>> import sys>>> sys.stdin.encoding ' GBK ' means our environment is GBK >>> import urllib>>> Urllib.quote (' coded pit Daddy ') '%b1%e0%c2%eb%bf%d3%b5%f9 '
So I got the URL code of GBK, directly to the URL with this code can directly explain the Chinese. We don't need to deal with it anymore.
>>> urllib.quote (' coded pit Daddy ' decode (' GBK '). Encode (' Utf-8 ')) '%e7%bc%96%e7%a0%81%e5%9d%91%e7%88%b9 '
This is the URL code for UTF-8.
Very convenient to solve the problem of another day ...
The above mentioned is the whole content of this article, I hope you can like.