接口_requests_基于python

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接口_requests_基于python相关的知识,希望对你有一定的参考价值。

HTTP request python官方文档:http://cn.python-requests.org/zh_CN/latest/

基于环境,需要安装requests 模块,安装方法 pip install requests
想学习requests,就通过help吧

import requests
help(requests)

返回结果如下:

C:\Python27\python.exe E:/test/interface/g_3.py
Help on package requests:

NAME
    requests

FILE
    c:\python27\lib\site-packages\requests\__init__.py

DESCRIPTION
    Requests HTTP Library
    ~~~~~~~~~~~~~~~~~~~~~
    
    Requests is an HTTP library, written in Python, for human beings. Basic GET
    usage:
    
       >>> import requests
       >>> r = requests.get(https://www.python.org)
       >>> r.status_code
       200
       >>> Python is a programming language in r.content
       True
    
    ... or POST:
    
       >>> payload = dict(key1=value1, key2=value2)
       >>> r = requests.post(http://httpbin.org/post, data=payload)
       >>> print(r.text)
       {
         ...
         "form": {
           "key2": "value2",
           "key1": "value1"
         },
         ...
       }
    
    The other HTTP methods are supported - see `requests.api`. Full documentation
    is at <http://python-requests.org>.
    
    :copyright: (c) 2017 by Kenneth Reitz.
    :license: Apache 2.0, see LICENSE for more details.

PACKAGE CONTENTS
    __version__
    _internal_utils
    adapters
    api
    auth
    certs
    compat
    cookies
    exceptions
    help
    hooks
    models
    packages
    sessions
    status_codes
    structures
    utils

FUNCTIONS
    check_compatibility(urllib3_version, chardet_version)

DATA
    __author__ = Kenneth Reitz
    __author_email__ = [email protected]
    __build__ = 137220
    __cake__ = u\u2728 \U0001f370 \u2728
    __copyright__ = Copyright 2017 Kenneth Reitz
    __description__ = Python HTTP for Humans.
    __license__ = Apache 2.0
    __title__ = requests
    __url__ = http://python-requests.org
    __version__ = 2.18.4
    codes = <lookup status_codes>

VERSION
    2.18.4

AUTHOR
    Kenneth Reitz



Process finished with exit code 0

获取requests所有的方法和类,就使用dir吧

import requests
print dir(requests)

返回如下:

[ConnectTimeout, ConnectionError, DependencyWarning, FileModeWarning, HTTPError, NullHandler, PreparedRequest, ReadTimeout, Request, RequestException, RequestsDependencyWarning, Response, Session, Timeout, TooManyRedirects, URLRequired, __author__, __author_email__, __build__, __builtins__, __cake__, __copyright__, __description__, __doc__, __file__, __license__, __name__, __package__, __path__, __title__, __url__, __version__, _internal_utils, adapters, api, auth, certs, chardet, check_compatibility, codes, compat, cookies, delete, exceptions, get, head, hooks, logging, models, options, packages, patch, post, put, request, session, sessions, status_codes, structures, urllib3, utils, warnings]

 


以上是关于接口_requests_基于python的主要内容,如果未能解决你的问题,请参考以下文章

基于Python+Requests库封装发送接口请求的工具类Python+Requests库做接口自动化框架设计系列多测师

python3+requests接口自动化-日志封装

python requests接口测试 -----博客园串接口

Python基于smtplib协议发送邮件Python+Requests库做接口自动化框架设计系列多测师

Python基于smtplib协议发送邮件Python+Requests库做接口自动化框架设计系列多测师

Python接口自动化--requests 2