def request(self, requestMethod, requestUrl, paramsType, requestData=None, headers=None, cookies=None):
if requestMethod.lower() == "post":
if paramsType == "form":
response = self.__post(url=requestUrl, data=json.dumps(eval(requestData)), headers=headers,cookies=cookies)
return response
elif paramsType == "json":
response = self.__post(url=requestUrl, json=json.dumps(eval(requestData)), headers=headers, cookies=cookies)
return response
eval、json.dumps:
-
eval function is to achieve conversion between str and list, dict, tuple
-
str function to list, dict, tuple into a string
-
Python is json.dumps converting a data structure of JSON
- requestData: {'username': 'zhangdongliang000', 'password': '9f4f4ec3d6fc9168cea54c4cc00c3eba'}
- type requestData: <class 'str'>
- Request parameters obtained, str is requestData type, i.e., "{ 'username': 'zhangdongliang000', 'password': '9f4f4ec3d6fc9168cea54c4cc00c3eba'}"
- By eval (requestData), two marks can be removed, it changes to dict type, i.e. { 'username': 'zhangdongliang000', 'password': '9f4f4ec3d6fc9168cea54c4cc00c3eba'}
- Then use json.dumps () to convert it to a string JSON (single quote), i.e., '{' username ':' zhangdongliang000 ',' password ':' 9f4f4ec3d6fc9168cea54c4cc00c3eba '}'
Note json string into a single quote after quote is a