• 导入模块
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请求的更多相关文章

  1. python爬虫 - python requests网络请求简洁之道

    http://blog.csdn.net/pipisorry/article/details/48086195 requests简介 requests是一个很实用的Python HTTP客户端库,编写 ...

  2. 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 ...

  3. python requests发起请求,报“Max retries exceeded with url”

    需要高频率重复调用一个接口,偶尔会出现"Max retries exceeded with url" 在使用requests多次访问同一个ip时,尤其是在高频率访问下,http连接 ...

  4. Python - requests https请求的坑

    #-*-coding:utf-8-*- # Time:2017/9/25 20:41 # Author:YangYangJun import requests import ssl from requ ...

  5. python + requests发起请求,接口返回400,报错“Unexpected character encountered while parsing value: G. Path”

    完整报错信息如下: {'errors': {'': ["Unexpected character encountered while parsing value: G. Path '', l ...

  6. Python+requests维持会话

    Python+requests维持会话 一.使用Python+requests发送请求,为什么要维持会话? 我们是通过http协议来访问web网页的,而http协议是无法维持会话之间的状态.比如说我们 ...

  7. 大概看了一天python request源码。写下python requests库发送 get,post请求大概过程。

    python requests库发送请求时,比如get请求,大概过程. 一.发起get请求过程:调用requests.get(url,**kwargs)-->request('get', url ...

  8. python requests 发起http POST 请求

    python requests 发起http POST 请求,带参数,带请求头: #!/usr/bin/env python # -*- coding: utf-8 -*- import reques ...

  9. Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据

    Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...

随机推荐

  1. Python处理数据

    由于找实习,要学习python处理数据,python连接mysql,python读写文件,python读写xlsx文件,这些只要引入了相关的包,就非常容易,处理过程非常清晰.模块如果封装的好,没怎么学 ...

  2. node.js 设置脚本命令

    yargs模块 https://www.npmjs.com/package/yargs https://github.com/yargs/yargs/blob/HEAD/docs/api.md con ...

  3. JVM内存GC的骗局——JVM不抛出OOM但内存已经泄露

    概述 在日常测试中,我们会去重点观察java的内存使用情况,比如:进程会抛出OOM异常,不再接收新的请求:响应时间在固定时间段内变长,超时或者不响应,CPU使用率时常像过山车一样等.有时候JVM还会发 ...

  4. ThinkPHP框架 自定义 Empty 方法保护本地信息不被暴露!!!

    在使用ThinkPHP框架开发过程中,在每个Controller文件夹里面都要设置一个空控制器,用来保护本地信息不被泄露(EmptyController.class.php) 此方法很有效的隐藏系统内 ...

  5. VBS数组导入Excel

    <script language="vbscript"> dim arr(9999,4) for i=0 to 9999 for j = 0 to 4 arr(i,j) ...

  6. Book118免费下载文档方法

    在book118上下载文件时,对于小文件可以使用冰点文库下载器来下载,而对于大文件,则可以使用下面的方法: 需要用的工具: 1.360浏览器 2.点“全屏预览”,然后把鼠标放在“下载该文档”,右键“审 ...

  7. Glufster挂载失败Mount failed. Please check the log file for more details解决办法

    设置两台glusterfs服务器主机名分别为gfs1,gfs2 设置好glusterfs挂载不成功提示如下 Mount failed. Please check the log file for mo ...

  8. 配置zsh

    .zshrc export ZSH="/root/.oh-my-zsh" ZSH_THEME="robbyrussell" plugins=(git zsh-s ...

  9. 业界微服务楷模Netflix是这样构建微服务技术架构的

    1. 如不考虑组织架构,直接切入技术架构(很多架构师的通病),则失败风险巨大. https://mp.weixin.qq.com/s/C8Rdz9wFtrBKfxPRzf0OBQ

  10. py 正则表达式 List的使用, cxfreeze打包

    从index.html当做检索出压缩文件,index.html的内容如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN& ...