UrlEncode and Quote_plus methods in the parse function in the Urllib module

Source: Internet
Author: User
Tags urlencode

Originally just to look at the role of Quote_plus, and then found that the UrlEncode method is also very convenient method of a combination of strings first is to introduce UrlEncode, he is some of the elements used in & concatenation, the effect is as follows:

>>>params = {            "AppID": 1,            "mch_id": 1,            "Body": 1,            "Out_trade_no": 1,            "Total_fee": 1,            "spbill_create_ip": 1,            "Notify_url": 1,            "Trade_type": 1,            "Nonce_str": 1}>>>parse.urlencode (params)'appid=1&mch_id=1&body=1&out_trade_no=1&total_fee=1&spbill_create_ip=1&notify_url= 1&trade_type=1&nonce_str=1'

If it is modified, it can be directly into the stitching string that generates the payment:

>>>parse.urlencode ([(k, Params[k]) forKinchsorted (params)])'Appid=1&body=1&mch_id=1&nonce_str=1&notify_url=1&out_trade_no=1&spbill_create_ip=1 &total_fee=1&trade_type=1'>>>[(k, params[k]) forKinchsorted (params)] [('AppID', 1), ('Body', 1), ('mch_id', 1), ('Nonce_str', 1), ('Notify_url', 1), ('Out_trade_no', 1), ('spbill_create_ip', 1), ('Total_fee', 1), ('Trade_type', 1)]

And then it was quote_plus, using a little bit of it. This method is to convert some special strings into a fixed number of symbolic alphanumeric combinations, for example:

>>>parse.quote_plus ('a&b/c')'A%26B%2FC  '

The & and/are changed into%26b and%2f, and there are some more symbolic changes that don't go to one by one.

UrlEncode and Quote_plus methods in the parse function in the Urllib module

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.