• 导入模块
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. Media Session API 为当前正在播放的视频,音频,提供元数据来自定义媒体通知

    google 文档 https://developers.google.cn/web/updates/2017/02/media-session <html lang="zh-cmn- ...

  2. 看看大神们是怎么解决一些【bng】的哪!!!!

    作者:姚冬  遇到bng的分享 我曾经做了两年大型软件的维护工作,那个项目有10多年了,大约3000万行以上的代码,参与过开发的有数千人,代码checkout出来有大约5个GB,而且bug特别多,op ...

  3. MPD软件工作坊上海站本周末在上海举行

    本周末(5月26日至27日)由麦思博(msup)主办的第39届MPD软件工作坊即将在上海虹桥会议中心举行.本届MPD将继续围绕软件研发领域,邀请了21位技术大咖,从产品运营.团队管理.架构技术.自动化 ...

  4. RMQ算法详解

    RMQ算法,是一个快速求区间最值的离线算法,预处理时间复杂度O(n*log(n)),查询O(1),所以是一个很快速的算法. 当然这个问题用线段树同样能够解决,算法复杂度为:O(N)~O(logN) . ...

  5. DevExpress前端组件库

    适用于为.Net环境(也有dephi版本,其他环境未知)下 WinForm\WebForm\ASP MVC的前端扩展组件,帮助生成高度windows office统一风格的界面. 在winform下, ...

  6. Java之旅_面向对象_重写和重载

    参考并摘自:http://www.runoob.com/java/java-override-overload.html 重写(Override) 子类对父类(允许访问的)方法的实现过程进行重新编写, ...

  7. ECharts图形库

    ECharts图形库百度的项目,图形的创建也比较简单,直接引用Javascript即可 1,引入<script src="{{ url_for("static",f ...

  8. Python pip 如何升级

    场景:部署环境时,在线安装第三方库(pip install flask-bootstrap),提示pip版本过低. 解决方法一:        命令: python -m pip install -- ...

  9. 洛谷P4823 拯救小矮人 [TJOI2013] 贪心+dp

    正解:贪心+dp 解题报告: 传送门! 我以前好像碰到过这题的说,,,有可能是做过类似的题qwq? 首先考虑这种显然是dp?就f[i][j]:决策到了地i个人,跑了j个的最大高度,不断更新j的上限就得 ...

  10. 10.7-uC/OS-III内部任务(定时器任务 OS_TmrTask())

    {这节所说的定时器都是软件定时器} 1.uC/OS-III为用户提供了定时器任务,相应代码在OS_TMR.C中.定时器任务是可选的,通过将OS_CFG.H中的OS_CFG_TMR_EN设置为1使能.当 ...