zoukankan      html  css  js  c++  java
  • 重载的方式写Python的get请求

    #encoding=utf-8
    #__author__="Lanyangyang"

    import unittest
    import requests
    import json

    # This is a public get method.
    def test_public_get(self, url, path, params):

    # get request method
    response = requests.get(url=url + path, params=params)

    # Is the return status code 200?
    self.assertEqual(response.status_code, 200, msg="The status code is not 200")

    # Is the return message SUCCESS?
    response_text = requests.get(url=url + path, params=params).text

    # Convert response content into dictionary format.
    response_dict = json.loads(response_text)

    # Gets the value of the response message.
    response_message = response_dict['message']

    #Determine the value of message.
    self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS')

    #Print response text.
    print(response.text)

    #Output text in JSON format
    response2 = requests.get(url=url + path, params=params).json()
    r = json.dumps(response2, indent=2, sort_keys=True)

    # Print response text in JSON format.
    print("The return information is as follows:")
    print(r)

    print("test_public_get call success.")



    # This is a public get method, include headers
    def test_public_get(self, url, path, params,headers):

    # get request method
    response = requests.get(url=url + path, params=params,headers=headers)

    # Is the return status code 200?
    self.assertEqual(response.status_code, 200, msg="The status code is not 200")

    # Is the return message SUCCESS?
    response_text = requests.get(url=url + path, params=params,headers=headers).text

    # Convert response content into dictionary format.
    response_dict = json.loads(response_text)

    # Gets the value of the response message.
    response_message = response_dict['message']

    # Determine the value of message.
    self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS')

    # Print response text.
    print(response.text)

    # Output text in JSON format
    response2 = requests.get(url=url + path, params=params,headers=headers).json()
    r = json.dumps(response2, indent=2, sort_keys=True)

    # Print response text in JSON format.
    print("The return information is as follows:")
    print(r)

    print("test_public_get call success.")



    # This is a public get method, include headers,no param
    def test_public_get(self, url, path,headers):

    # get request method
    response = requests.get(url=url + path,headers=headers)

    # Is the return status code 200?
    self.assertEqual(response.status_code, 200, msg="The status code is not 200")

    # Is the return message SUCCESS?
    response_text = requests.get(url=url + path, headers=headers).text

    # Convert response content into dictionary format.
    response_dict = json.loads(response_text)

    # Gets the value of the response message.
    response_message = response_dict['message']

    # Determine the value of message.
    self.assertEqual(response_message, 'SUCCESS', msg='The response message is not SUCCESS')

    # Print response text.
    print(response.text)

    # Output text in JSON format
    response2 = requests.get(url=url + path,headers=headers).json()
    r = json.dumps(response2, indent=2, sort_keys=True)

    # Print response text.
    print("The return information is as follows:")
    print(r)

    print("test_public_get call success")
  • 相关阅读:
    uml系列(四)——类图
    Linux设备驱动实现自己主动创建设备节点
    收集了三年的最好的设计站点
    CoInitialize浅析一
    iOS 单例
    Android开发之异步具体解释(二)之AsyncTask
    ComboBox控件
    下拉框Html.DropDownList 和DropDownListFor 的经常用法
    好记心不如烂笔头,ssh登录 The authenticity of host 192.168.0.xxx can't be established. 的问题
    cidaemon.exe进程cpu占用率高及关闭cidaemon.exe进程方法
  • 原文地址:https://www.cnblogs.com/lanyy/p/10420425.html
Copyright © 2011-2022 走看看