Solve the Problem of passing Chinese parameters in Python

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.