Use the Python interface test dumps of eval, json of

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

  1. requestData: {'username': 'zhangdongliang000', 'password': '9f4f4ec3d6fc9168cea54c4cc00c3eba'}
  2. type requestData: <class 'str'>
  3. Request parameters obtained, str is requestData type, i.e., "{ 'username': 'zhangdongliang000', 'password': '9f4f4ec3d6fc9168cea54c4cc00c3eba'}"
  4. By eval (requestData), two marks can be removed, it changes to dict type, i.e. { 'username': 'zhangdongliang000', 'password': '9f4f4ec3d6fc9168cea54c4cc00c3eba'}
  5. 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

Guess you like

Origin blog.csdn.net/chang_jinling/article/details/89968134