This article mainly describes how to solve the problem of passing Chinese parameters in Python. For more information, see the following:
However, in the GBK environment, the parameter transmitted by the script to GBK always reports UNICODE decoding errors to me. Annoying.
Therefore, we decided to use urlencode to process Chinese characters,
Because of the different codes of domestic and foreign websites, the domestic code is GBK and the foreign code is UTF8.
>>> Import sys >>> sys. stdin. encoding 'gbk' indicates that our environment is GBK >>>> import urllib >>> urllib. quote ('encoding badge') '% B1 % E0 % C2 % EB % BF % D3 % B5 % f9'
In this way, I get the GBK url encoding, which can be directly transferred to the URL to directly explain the Chinese language. We don't need to deal with it anymore.
>>> Urllib. quote '. decode ('gbk '). encode ('utf-8') '% E7 % BC % 96% E7 % A0 % 81% E5 % 9D % 91% E7 % 88% b9'
This is the URL code for the UTF-8
It is very convenient to solve the problem of another day...
The above is all the content of this article. I hope you will like it.