Record the acquisition of the GET method in the interface test

Here is an introduction to the get method. In fact, you can look at the introduction in the source code for these methods. You only need to enter the code:

import requests

help(requests)

You can see the explanation with examples:

Insert picture description here
Now let's complete the second step of RF interface testing: sending the request.
The modules that Python sends http requests mainly include requests, urllib, and urllib2. Here we introduce the simplest requests module among the three.
Install the requests module: pip install requests

1、get

After importing the requests, you can use the get method to directly access the url:

#coding: utf-8import requestsclass SendingInfo(object):    ROBOT_LIBRARY_SCOPE = 'GLOBAL'
    ROBOT_LIBRARY_VERSION = '0.1'

    def __init__(self):
        pass

    def sending_info(self):
        rs = requests.get('https://www.baidu.com')
        #打印状态码
        print rs.status_code
        #打印返回html
        print rs.content
        #打印头文件信息
        print rs.headers
        #打印cookies
        print rs.cookies

If you want to exchange experience in software testing, interface testing, automated testing, and interviews. If you are interested, you can add software test communication: 313782132, and there will be technical exchanges with colleagues.
After instantiating the class, call the function to see the printed return:

Insert picture description here
In addition to the information printed above, you can also see more information:

rs.url -- 获取url
rs.json() -- Requests中内置的Json解码器
rs.text -- 字符串方式的响应体,会自动根据响应头部的字符编码进行解码。与r.content相比rs.text可能会有乱码。
rs.encoding -- 编码格式

The above is the acquisition of the GET method. The content hopes to be helpful to you. Although this is not difficult, friends who have been helped are welcome to like and comment.

Software testing is the easiest subject in IT-related industries to get started~ It does not require the logical thinking of developers, and operations and maintenance personnel are not required to be on call 24 hours a day. What is needed is a careful attitude and a broad understanding of IT-related knowledge. The growth path of each tester from entering the industry to becoming a professional expert can be divided into three stages: software testing, automated testing, and test development engineers.

Insert picture description here

Here are some information I have compiled. If you don’t want to experience the self-study again, you can’t find the information, no one answers the question, and you feel like giving up after a few days, you can add our software testing exchange group 313782132, which contains various software Test data and technical exchanges.

Guess you like

Origin blog.csdn.net/weixin_50271247/article/details/109331034