The code is as follows:
Import JSON Import = requests.post (url, data = {"a": Json.dumps ({"b" ) " C " # url is random URL
Use Fiddler to grab the package, although in WebForms you see the format as follows:
But see the results in raw as follows:
That is, automatic execution of the UrlEncode, view requests/models.py source code discovery, if the data can be iterated, that is, automatically join the "application/x-www-form-urlencoded" header, and perform UrlEncode:
In the Prepare_body method of the Preparedrequest class
if Data: = self._encode_params (data) ifor'read'): = None Else: 'application/ x-www-form-urlencoded'
In the _encode_params (data) method of the Requestencodingmixin class
ifisinstance (data, (str, bytes)):returnDataelifHasattr (data,'Read'): returnDataelifHasattr (data,'__iter__'): Result= [] forK, vsinchto_key_val_list (data):ifIsinstance (VS, basestring)or notHasattr (VS,'__iter__'): vs=[vs] forVinchvs:ifV is notNone:result.append ((K.encode ('Utf-8')ifIsinstance (k, str)ElseK, V.encode ('Utf-8')ifIsinstance (V, str)Elsev))returnUrlEncode (Result, doseq=True)Else: returnData
Workaround:
Import JSON Import = {"content-type""application/x-www-form-urlencoded" "a=%s"% Json.dumps ({"B" " C " = requests.post (URL, data = data, headers = headers);
Python-requests JSON problem with post data