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¬ify_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¬ify_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