Requests API
http://docs.python-requests.org/zh_CN/latest/api.html
发送请求requerts
参数 | 类型 | 描述 |
---|---|---|
method | str | ‘get’/'post’等 |
url | str | 请求的网页,注意post的时候提交数据对应的页面是form的action |
params | dict | url里面的参数 |
data | dict | post方法的时候提交的dict,在body里 |
json | ||
headers | dict | 表头 |
cookies | dict or CookieJar | 可以通过第一次的response来获得 |
files | dict | value对应的是file类型的文件,既open()函数返回的对象 |
auth | ||
timeout | float | 等待返回的时间,超过就放弃请求 |
proxies | dict | 代理ip设置 |
stream | boolean | 是否以流的形式返回,默认false |
verify | boolean | 是否验证安全证书,如果遇到验证不通过直接写false |
params参数可以用字典的形式传入,也可以在url里直接用"?"来连接参数
poxies格式,根据不同的协议选择不同的ip
proxies = {"http": "http://12.34.56.78:9000","https": "http://12.34.56.78:9000",
}
发送请求的7中方法
- requests.request(method, url, **kwargs)
- requests.head(url, **kwargs)
- requests.get(url, params=None, **kwargs)
- requests.put(url, data=None, **kwargs)
- requests.patch(url, data=None, **kwargs)
- requests.delete(url, **kwargs)
get常用方法
requests.get(url, params=None, **kwargs)发送一个get请求
参数 | 描述 |
---|---|
url | 网页地址 |
params | 网页参数 |
headers | 表头参数 |
timeout | 等待时间 |
proxies | IP代理 |
stream | 二进制格式返回 |
返回类型:requests.Response
请求对话
class requests.Session
属性
属性 | 描述 |
---|---|
self.headers | |
self.auth | |
self.proxies | |
self.hooks | |
self.params = {} | |
self.stream = False | |
self.verify = True | |
self.cert = None | |
self.max_redirects | |
self.trust_env | |
self.cookies | |
self.adapters | |
self.redirect_cache |
对象方法
方法 | 描述 |
---|---|
def prepare_request(self, request) | |
def request() | |
def get(self, url, **kwargs) | |
def options(self, url, **kwargs) | |
def head(self, url, **kwargs) | |
def post(self, url, data=None, json=None, **kwargs) | |
def put(self, url, data=None, **kwargs) | |
def patch(self, url, data=None, **kwargs) | |
def delete(self, url, **kwargs) | |
def send(self, request, **kwargs) | |
def merge_environment_settings(self, url, proxies, stream, verify, cert) | |
def get_adapter(self, url) | |
def close(self) | |
def mount(self, prefix, adapter) |
查看响应内容Response对象
对象属性
属性 | 描述 |
---|---|
.status_code | HTTP响应状态,比如404或200(int) |
.headers | 获得响应头(dict) |
.raw | 返回原始数据,需要设置stream=True(file-like) |
.url | 最后的连接(str) |
.encoding | 设置编码格式(str) |
.history | 获得重定向连接(list) |
.reason | 响应状态的翻译(str) |
.cookies | 获得cookie(CookieJar) |
.elapsed | 获得响应时间 |
.request | 返回PreparedRequest对象 |
.ok | 是否连接成功(bool) |
.is_redirect | 是否重定向(bool) |
.is_permanent_redirect | |
.apparent_encoding | 返回编码(str) |
.content | 返回二进制(str) |
.text | 返回文本(str) |
.links | 返回网址(list) |
对象方法
方法 | 描述 |
---|---|
ok(self) | 是否连接成功(bool) |
is_redirect(self) | 是否重定向(bool) |
is_permanent_redirect(self) | |
apparent_encoding(self) | 返回编码(str) |
iter_content(self, chunk_size=1, decode_unicode=False) | 二进制迭代 |
iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=None, delimiter=None) | 内容迭代 |
content(self) | 返回二进制(str) |
text(self) | 返回文本(str) |
json(self, **kwargs) | 返回json |
links(self) | 返回网址(list) |
raise_for_status(self) | 返回错误信息 |
close(self) | 释放连接 |
cookie
class requests.cookies.RequestsCookieJar(policy=None)
方法 | 描述 |
---|---|
get_dict(domain=None, path=None) | 返回cookie对应的字典 |
Requests API相关推荐
- pythonrequest方法_解决Python requests 报错方法集锦
python版本和ssl版本都会导致 requests在请求https网站时候会出一些错误,最好使用新版本. 1 Python2.6x use requests 一台老Centos机器上跑着古老的应用 ...
- 科大讯飞语音合成api
import base64import jsonimport timeimport hashlibimport requests # API请求地址.API KEY.APP ID等参数,提前填好备用a ...
- pythonrequests说明_解决Python requests 报错方法集锦
python版本和ssl版本都会导致 requests在请求https网站时候会出一些错误,最好使用新版本. 1 Python2.6x use requests 一台老Centos机器上跑着古老的应用 ...
- Python requests介绍之接口介绍
Python requests介绍 引用官网介绍 Requests 唯一的一个非转基因的 Python HTTP 库,人类可以安全享用. Requests 允许你发送纯天然,植物饲养的 HTTP/1. ...
- python requests https_解决python的requests模块访问私有SSL证书产生的报错问题
如题访问部分私有SSL证书网站时报如下错误 requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate ver ...
- python requests 上传文件_Python requests上传文件实现步骤
工作中涉及到一个功能,需要上传附件到一个接口,接口参数如下: 使用http post提交附件 multipart/form-data 格式,url : http://test.com/flow/upl ...
- requests模块报错:Use body.encode('utf-8') if you want to send it encoded in UTF-8.
在做 企业向微信用户个人付款 功能时,调用第三方sdk,在 进行 requests 的post请求时, 代码如下 req = requests.post(url, data=data,cert(ap ...
- Python文摘:Requests (Adavanced Usage)
原文地址:http://docs.python-requests.org/en/latest/user/advanced/#advanced Advanced Usage¶ This document ...
- python的requests快速上手、高级用法和身份认证
https://blog.csdn.net/qq_25134989/article/details/78800209 快速上手 迫不及待了吗?本页内容为如何入门 Requests 提供了很好的指引.其 ...
最新文章
- python报错:TypeError: cant multiply sequence by non-int of type float(bug)(csdn标题没法用英文引号,以后注意别搜引号)
- 使用go build 进行条件编译
- element ui 组件踩坑记录--后台管理系统-最全
- 解决网页中不能复制文字的问题
- mfc判断文件是否被读写_迅为干货|标准io之一个字符的读写函数
- mysql中将int转为_mysql – 将int转换为varchar
- 台式计算机M丅BF是什么,中南民族大学计算机系统结构试卷
- VMware12提示 已将该虚拟机配置为使用 64 位客户机操作系统。但是,无法执行 64 位操作。...
- Cisco IOS Site-to-Site Pre-share Key ×××
- 夏侯南溪搭建目标检测模型——文件结构设计篇
- 【Visual C++】游戏开发笔记三十四 浅墨DirectX提高班之三 起承转合的艺术:Direct3D渲染五步曲...
- 为什么每个邮件收到后都会有一个htm的附件_Python3.x 发送各种形式的告警邮件内容...
- Python安装完成 运行的时候报错 0xc000007b
- SBUS调试助手 sbus解析,sbus协议
- 【常见的检索源期刊】SCI+EI(核心)+ISTP+CSSCI+SSCI+AHCI简介
- 松下弧焊机器人 调电压_松下焊接机器人操作规程
- php ioncube encoder,Ioncube PHP Encoder
- 梦幻西游跑商脚本教程
- C#中的几个线程同步对象
- 2017兰州高中计算机考试时间,兰州2017年中考考试时间安排
热门文章
- 微课--25分钟学会使用Python群发电子邮件
- Python快速判断若干整数是否互不相同
- 微课|玩转Python轻松过二级(2.4节):常用内置函数用法精要3
- linux如何更新数据包up,Linux更新(update/upgrade) 修改更新源
- seir模型数学建模python_Python改进的SEIR模型
- python调用库函数用ecb模式加密图片_python 实现AES加密解密(ECB模式,配合base64)...
- dom文档对象手册_编程小白网页学习笔记之文档对象模型(DOM)
- python读取xml文件内容_python读取xml文件
- console线驱动安装_文通证件识别SDK和驱动安装使用说明
- linux 让暂停的进程恢复,Linux 下进程的挂起和恢复命令