python requests http请求
- 导入模块
import requests
import json header = {'Content-Type': 'application/json'}
data = {"": ""}
data = json.dumps(data)
endpoint = "http://www.baidu.com/"
- 常用操作
request = requests.get(endpoint + "get")
request = requests.head(endpoint + "get")
request = requests.delete(endpoint + "delete")
request = requests.options(endpoint + "options")
request = requests.put(endpoint + "put",data=data)
request = requests.post(endpoint + "post", data=data, headers=header)
- 不验证https证书
request = requests.get(endpoint,verify=False)
- 请求超时
request = requests.get(endpoint,timeout=5)
- 测试url是否正常
try:
data = str(requests.head('http://www.baidu.com', timeout=5))
except:
print("有问题")
else:
print("没问题")
- 打印返回
#打印返回的http状态码
print(request.status_code)
#打印请求的地址
print(request.url)
#json格式打印返回的数据
print(request.json())
#文本格式打印返回的数据
print(request.text)
python requests http请求的更多相关文章
- python爬虫 - python requests网络请求简洁之道
http://blog.csdn.net/pipisorry/article/details/48086195 requests简介 requests是一个很实用的Python HTTP客户端库,编写 ...
- Python - requests发送请求报错:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 13-14: 小明 is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.
背景 在做接口自动化的时候,Excel作为数据驱动,里面存了中文,通过第三方库读取中文当请求参数传入 requests.post() 里面,就会报错 UnicodeEncodeError: 'lati ...
- python requests发起请求,报“Max retries exceeded with url”
需要高频率重复调用一个接口,偶尔会出现"Max retries exceeded with url" 在使用requests多次访问同一个ip时,尤其是在高频率访问下,http连接 ...
- Python - requests https请求的坑
#-*-coding:utf-8-*- # Time:2017/9/25 20:41 # Author:YangYangJun import requests import ssl from requ ...
- python + requests发起请求,接口返回400,报错“Unexpected character encountered while parsing value: G. Path”
完整报错信息如下: {'errors': {'': ["Unexpected character encountered while parsing value: G. Path '', l ...
- Python+requests维持会话
Python+requests维持会话 一.使用Python+requests发送请求,为什么要维持会话? 我们是通过http协议来访问web网页的,而http协议是无法维持会话之间的状态.比如说我们 ...
- 大概看了一天python request源码。写下python requests库发送 get,post请求大概过程。
python requests库发送请求时,比如get请求,大概过程. 一.发起get请求过程:调用requests.get(url,**kwargs)-->request('get', url ...
- python requests 发起http POST 请求
python requests 发起http POST 请求,带参数,带请求头: #!/usr/bin/env python # -*- coding: utf-8 -*- import reques ...
- Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据
Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...
随机推荐
- 关于思科C2950交换机清除密码,恢复初始配置的方法
上个月河南做项目,因需要大批量的对服务器进行操作系统的安装,于是想到了PXE网络批量安装, 好不容易到机房的仓库找到网线及一台思科交换机,但到安装的时候,发现思科交换机里应该有配置了 通过配置线连接交 ...
- F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- 遍历DOM打平
html 模板 <div class="box"> <p>1</p> <p>2</p> <div> < ...
- c语言中的左移和右移
先说左移,左移就是把一个数的所有位都向左移动若干位,在C中用<<运算符.例如: int i = 1;i = i << 2; //把i里的值左移2位 也就是说,1的2进制是00 ...
- ELK之elasticsearch6安装认证模块search guard
参考:https://www.cnblogs.com/marility/p/9392645.html 1,安装环境及软件版本 程序 版本 安装方式 elasticsearch 6.3.1 rpm ...
- MySql 远程连接的条件
1.首先看服务器防火墙 引用:http://www.cnblogs.com/silent2012/archive/2015/07/28/4682770.html CentOS 7.0默认使用的是fir ...
- js callback 和 js 混淆
function test(a,callback){ a+=100; callback(a) } function abc(a){ a+=100; alert(a); } test(5,abc) js ...
- 文末有福利 | IT从业者应关注哪些技术热点?
7月14-15日,MPD工作坊北京站即将开幕,目前大会日程已经出炉,来自各大企业的技术专家,按照软件研发中心的岗位职能划分,从产品运营.团队管理.架构技术.自动化运维等领域进行干货分享,点击此[链接] ...
- ThinkPad X1 Carbon 2018 Windows 10无法关机的问题
最近两天在工作中很多同事都遇到了自己的X1电脑关机时自动重启的现象,这个问题让我在知乎.微软支持.国外各种科技论坛找到了很多类似的症状. 但是针对同事们遇到的问题,解决方案异常的简单:就是下载联想驱动 ...
- [No0000103]JavaScript-基础课程3
在 JavaScript 中,函数的参数是比较有意思的,比如,你可以将任意多的参数传递给一个函数,即使这个函数声明时并未制定形式参数 function adPrint(str, len, option ...