Python and php communication garbled problem solution

Source: Internet
Author: User
Python is a client in windows and uses cp936 encoding. php uses UTF-8 encoding. if post is sent after urlencode encoding, the Chinese characters received by php will be encoded in the form of xb0xe1, even before urlencode. decode ("cp936 ″). encode ("UTF-8") is useless after encoding conversion. Later, I found a urllib. quote () function in the query Manual. this method was used to solve the problem!
Python:

The code is as follows:


Str = "Chinese"
Str = urllib. quote (str. decode ("cp936"). encode ("UTF-8 "))
PostData = {}
PostData ['str'] = str
... Post request sending code...


Php:

The code is as follows:


$ Str = urldecode ($ _ POST ['str'])
Echo $ str;


Solve the garbled problem perfectly!

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.