Python requests介绍

引用官网介绍

Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用。

Requests 允许你发送纯天然,植物饲养的 HTTP/1.1 请求,无需手工劳动。你不需要手动为 URL 添加查询字串,也不需要对 POST 数据进行表单编码。Keep-alive 和 HTTP 连接池的功能是 100% 自动化的,一切动力都来自于根植在 Requests 内部的 urllib3。

功能特性

Requests 完全满足今日 web 的需求。

  • Keep-Alive & 连接池
  • 国际化域名和 URL
  • 带持久 Cookie 的会话
  • 浏览器式的 SSL 认证
  • 自动内容解码
  • 基本/摘要式的身份认证
  • 优雅的 key/value Cookie
  • 自动解压
  • Unicode 响应体
  • HTTP(S) 代理支持
  • 文件分块上传
  • 流下载
  • 连接超时
  • 分块请求
  • 支持 .netrc

Requests 支持 Python 2.6—2.7以及3.3—3.7,而且能在 PyPy 下完美运行。

''' requests 接口介绍  '''
#-*-coding:utf-8-*-
# Time:2017/10/12 22:54
# Author:YangYangJun#开始 requests学习之旅,这里直接在代码编写文字了。#requests 是python的第三方库,所以这里需要安装# 直接在命令行窗口执行 pip install requests  即可#如果提示安装失败,可以参看提示,安装必备软件然后重新安装即可#安装成功后 即可直接导入import  requests#如上不报错即可#参考资料#访问网址 http://cn.python-requests.org/zh_CN/latest/  即可查看官方中文文档#或是查看源代码  https://github.com/requests/requests#也可到 自己的安装目录下查找 D:/SProgram/Python/Lib/site-packages/requests/api.py 等文件查看介绍''' requests 接口介绍  '''
# 这部分文档包含了 Requests 所有的接口。对于 Requests 依赖的外部库部分,我们在这里介绍最重要的部分,并提供了规范文档的链接。
#
# 主要接口
# Requests 所有的功能都可以通过以下 7 个方法访问。它们全部都会返回一个 Response 对象的实例。# 1、request()方法
# requests.request(method, url, **kwargs)   Constructs and sends a Request. 构造和发送请求。
# 这里的参数 method 、 url 是必选参数,**kwargs 是可选参数,是 可变关键字参数,Dictionary 类型
'''
参数:
method -- method for the new Request object.
新请求对象的方法
url -- URL for the new Request object.
新的请求对象的URL
params -- (optional) Dictionary or bytes to be sent in the query string for the Request.
(可选)在查询字符串中为请求发送的字典或字节。
data -- (optional) Dictionary or list of tuples [(key, value)] (will be form-encoded), bytes, or file-like object to send in the body of the Request.
(可选)字典或元组列表[(键,值)](将以表单编码)、字节或类似文件的对象发送到请求体中。
json -- (optional) json data to send in the body of the Request.
(可选)json数据发送到请求体中。
headers -- (optional) Dictionary of HTTP Headers to send with the Request.
(可选)HTTP报头字典,以发送请求。
cookies -- (optional) Dict or CookieJar object to send with the Request.
(可选)命令或CookieJar对象发送请求。
files -- (optional) Dictionary of 'name': file-like-objects (or {'name': file-tuple}) for multipart encoding upload. file-tuple can be a 2-tuple
('filename', fileobj), 3-tuple ('filename', fileobj, 'content_type') or a 4-tuple ('filename', fileobj, 'content_type', custom_headers),
where 'content-type' is a string defining the content type of the given file and custom_headers a dict-like object containing additional
headers to add for the file.
438/5000
(可选)“名称”的字典:文件- like- object(或{' name ':file - tuple}),用于多部分编码上传。文件- tuple可以是一个2元组(文件名,fileobj),
3元组(文件名,fileobj,' content_type ')或一个4元组(' filename ',fileobj,' content_type ',custom_headers),
其中' content-type '是一个字符串,它定义了给定文件的内容类型和custom_headers,其中包含了一个类似于dict的对象,其中包含了添加文件的附加头文件。auth -- (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
(可选)Auth tuple来启用Basic /Digest /自定义HTTP Auth。
timeout (float or tuple) -- (optional) How many seconds to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.
(可选)在放弃之前,等待服务器发送数据的时间是多少秒,作为一个浮点数,或者是一个(连接超时,读超时)元组。
allow_redirects (bool) -- (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to True.
(可选)布尔。启用/禁用GET /选项/ POST / PUT /补丁/删除/头重定向。默认值为True。
proxies -- (optional) Dictionary mapping protocol to the URL of the proxy.
(可选)字典映射协议到代理的URL。
verify -- (optional) Either a boolean, in which case it controls whether we verify the server's TLS certificate, or a string, in which case it must be a path to a CA bundle to use. Defaults to True.
(可选)一个布尔值,在这种情况下,它控制我们是否验证服务器的TLS证书,或者是一个字符串,在这种情况下,它必须是一个到CA包使用的路径。默认值为True。
stream -- (optional) if False, the response content will be immediately downloaded.
(可选)如果错误,将立即下载响应内容。
cert -- (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
(可选)如果字符串,路径到ssl客户机cert文件(. pem)。如果是Tuple(' cert ',' key ')对。
'''# request()方法实例
req = requests.request('GET', 'http://httpbin.org/get')print req
# 得到 <Response [200]># 2、head()方法# requests.head(url, **kwargs)
# Sends a HEAD request.  发送一个HEAD 请求。# Optional arguments that ``request`` takes.  请求获取的可选参数。
r"""Sends a HEAD request.:param url: URL for the new :class:`Request` object.:param \*\*kwargs: Optional arguments that ``request`` takes.  :return: :class:`Response <Response>` object  :rtype: requests.Response"""
# head()方法实例
req = requests.head('http://httpbin.org/get')print req
# 得到 <Response [200]># 3、get()方法# requests.get(url, params=None, **kwargs)[源代码]
# Sends a GET request.
#
# 参数:
# url -- URL for the new Request object.
# params -- (optional) Dictionary or bytes to be sent in the query string for the Request.
# **kwargs -- Optional arguments that request takes.
# 返回:
# Response object
#
# 返回类型:
# requests.Response# get()方法实例
req = requests.get('http://httpbin.org/get')print req
# 得到 <Response [200]># 4、post()方法# requests.post(url, data=None, json=None, **kwargs)[源代码]
# Sends a POST request.
#
# 参数:
# url -- URL for the new Request object.
# data -- (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the Request.
# json -- (optional) json data to send in the body of the Request.
# **kwargs -- Optional arguments that request takes.
# 返回:
# Response object
#
# 返回类型:
# requests.Response# post()方法实例
req = requests.post('http://httpbin.org/get')print req
# 得到 <Response [405]># 5、put()方法# requests.put(url, data=None, **kwargs)[源代码]
# Sends a PUT request.
#
# 参数:
# url -- URL for the new Request object.
# data -- (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the Request.
# json -- (optional) json data to send in the body of the Request.
# **kwargs -- Optional arguments that request takes.
# 返回:
# Response object
#
# 返回类型:
# requests.Response# 6、patch()方法# requests.patch(url, data=None, **kwargs)[源代码]
# Sends a PATCH request.
#
# 参数:
# url -- URL for the new Request object.
# data -- (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the Request.
# json -- (optional) json data to send in the body of the Request.
# **kwargs -- Optional arguments that request takes.
# 返回:
# Response object
#
# 返回类型:
# requests.Response# 7、delete()方法# requests.delete(url, **kwargs)[源代码]
# Sends a DELETE request.
#
# 参数:
# url -- URL for the new Request object.
# **kwargs -- Optional arguments that request takes.
# 返回:
# Response object
#
# 返回类型:
# requests.Response
#

转载于:https://www.cnblogs.com/BlueSkyyj/p/7652860.html

Python requests介绍之接口介绍相关推荐

  1. Python requests模块相关接口

    2019独角兽企业重金招聘Python工程师标准>>> 主要接口 Requests 所有的功能都可以通过以下 7 个方法访问.它们全部都会返回一个 Response 对象的实例. r ...

  2. 【接口自动化学习笔记】python+requests+excel实现接口自动化

    文章内容参考:pytest+requests+Excel+allure接口自动化测试框架实践_JJJims的博客-CSDN博客 功能        excel驱动的接口自动化+邮件发送 背景 参考了上 ...

  3. python web api 自动化测试_基于Python + requests 的web接口自动化测试框架

    之前采用JMeter进行接口测试,每次给带新人进行培训比较麻烦,干脆用python实现,将代码和用例分离,易于维护. 项目背景 公司的软件采用B/S架构,进行数据存储.分析.管理 工具选择 pytho ...

  4. python+requests+unittest+excel_接口自动化测试 unittest+request+excel(踩‘坑’)

    通过运行主函数,返回的参数,报json解析错误 正常的返回参数,应该如图 造成这个原因的是: python从excel中解析出来的数据类型不是字典,是字符串,所以无法传递给requests当做请求参数 ...

  5. QGC地面站二次开发(一)地面站介绍以及软件框架(1)地面站使用介绍和接口介绍

    目录 QGC界面显示框架 页面介绍 飞行页面 Application Setting页面 General Offline map 连接 Mock Link Vehicle Setup页面 Plan页面 ...

  6. 基于Python Requests的数据驱动的HTTP接口测试

    发表于:2017-8-30 11:56  作者:顾翔   来源:51Testing软件测试网原创 http://www.51testing.com/html/69/n-3720769-2.html 1 ...

  7. 遨博协作机器人高级编程 -AUBOPE SDK Python接口介绍与使用

    目录 一.简介 二.环境版本 三.Python SDK接口简介 1.Python SDK接口数据 2. Python SDK接口函数示例 四.任务实施 五.任务拓展 一.简介 大家好,本篇文章主要针对 ...

  8. 百度API实现logo商标识别接口介绍

    作者介绍 严松,男,西安工程大学电子信息学院,2022级研究生 研究方向:机器人抓取检测 电子邮件:2448052777@qq.com 祝樱,女,西安工程大学电子信息学院,2022级研究生 研究方向: ...

  9. python–爬虫–模拟登录全面介绍和简例–以抓取雅卓app为例

    转载请注明出处:python–爬虫–模拟登录全面介绍和简例–以抓取雅卓app为例 我们在前面的文章中已经学习了如果使用python进行数据抓取. 但我们常常会遇到一种场景,就是想要获取的页面内容或者接 ...

最新文章

  1. 互联网人必读的30本书
  2. 强化科技硬实力 厚植创新软实力——访中国科学院院士唐本忠
  3. Java开发需掌握的常用Linux命令(持续更新)
  4. IT.如何选择转型?
  5. pythonmessage用法_django 消息框架 message使用详解
  6. python学法用法 自动刷分器_Python selenium模拟手动操作实现无人值守刷积分功能...
  7. C#多线程之旅(1)——介绍和基本概念
  8. C++ STL string的属性
  9. The Network Adapter could not establish the connection解决
  10. 如果在安卓后台杀死程序怎么进行保存
  11. 面试官:谈谈分布式一致性机制,我一脸懵逼。。
  12. 慕课马尔萨斯人口模型
  13. Excel-VBA基础(11):VBA中数组基础知识
  14. 实用,开源,生成朋友圈转发点赞截图小工具一枚
  15. 编程求球的体积和表面积(c语言)
  16. UniApp引入极光推送
  17. java基础代码练习
  18. MacOS redis开机启动设置
  19. 半自动化批量下载专利全文pdf傻瓜攻略
  20. 为 CentOS 配置网络

热门文章

  1. antd 表单域验证规则 - 只能输入数字字符,去除前导0
  2. vue-cli3项目通过vue如何引入第三方js包完成登陆功能
  3. 网络IPC非阻塞和异步I/O
  4. 前端面试题vue-element汇总
  5. [react] React中在哪捕获错误?
  6. 深入react技术栈(6):React和DOM
  7. javascript学习系列(12):数组中的join方法
  8. 前端学习(3205):对state的理解
  9. [vue] vue怎么改变插入模板的分隔符?
  10. [css] 用css实现饼图效果