python requests 发起http POST 请求,带参数,带请求头:

#!/usr/bin/env python
# -*- coding: utf-8 -*- import requests
import json url = 'http://official-account/app/messages/group'
body = {"type": "text", "content": "测试文本", "tag_id": "20717"}
headers = {'content-type': "application/json", 'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8'}

#print type(body)
#print type(json.dumps(body)) # 这里有个细节,如果body需要json形式的话,需要做处理
# 可以是data = json.dumps(body)
response = requests.post(url, data = json.dumps(body), headers = headers) # 也可以直接将data字段换成json字段,2.4.3版本之后支持
# response = requests.post(url, json = body, headers = headers)

# 返回信息
print response.text # 返回响应头
print response.status_code

  

python requests 发起http POST 请求的更多相关文章

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

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

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

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

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

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

  4. python - 怎样使用 requests 模块发送http请求

    最近在学python自动化,怎样用python发起一个http请求呢? 通过了解 request 模块可以帮助我们发起http请求 步骤: 1.首先import 下 request 模块 2.然后看请 ...

  5. 用python的Requests库模拟http请求

    一.先了解几个重要的http请求头或响应头信息 Request Headers: Host: 描述请求将被发送的目的地,包括,且仅仅包括域名和端口号. Origin: 说明请求从哪里发起的,包括,且仅 ...

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

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

  7. python+requests 请求响应文本出错返回“登录超时”

    Python+requests请求响应:"msg":"登录过时" 1.出错原代码: import requests import json#页面按条件搜索返回相 ...

  8. Python接口测试-使用requests模块发送GET请求

    本篇主要记录下使用python的requests模块发送GET请求的实现代码. 向服务器发送get请求:无参数时:r = requests.get(url)带params时:r = requests. ...

  9. Python接口测试-使用requests模块发送post请求

    本篇主要记录下使用python的requests模块发送post请求的实现代码. #coding=utf-8 import unittest import requests class PostTes ...

随机推荐

  1. js 的深拷贝

    出处:https://www.cnblogs.com/Chen-XiaoJun/p/6217373.html function deepClone(initalObj, finalObj) { var ...

  2. 代码风格统一工具:EditorConfig 和 静态代码检查工具:ESLint

    EditorConfig 最常见的用途是:统一文件的编码字符集以及缩进风格 使用 Eslint 做代码 lint,那么为什么还要使用 .editorconfig 呢?细细想了下,应该有两个方面吧. E ...

  3. streaming简介

    mapreduce和hdfs采用java实现,默认提供java编程接口 streaming框架允许任何程序语言实现的程序在hadoop mapreduce中使用 streaming方便已有的程序向ha ...

  4. 单机RedHat6.5+JDK1.8+Hadoop2.7.3+Spark2.1.1+zookeeper3.4.6+kafka2.11+flume1.6环境搭建步骤

    1.RHEL 6.5系统安装配置图解教程(rhel-server-6.5) 2.在Linux下安装JDK图文解析 3.RedHat6.5上安装Hadoop单机 4.RedHat6.5安装Spark单机 ...

  5. mysql 删除数据库中所有的表中的数据,只删database下面所有的表。

    select concat('drop table ',table_name,';') from TABLES where table_schema='数据库名称'; select concat('t ...

  6. webdriver 启动chrome时加载配置

    Selenium操作浏览器是不加载任何配置的,网上找了半天,关于Firefox加载配置的多点,Chrome资料很少,下面是关于加载Chrome配置的方法:  一.加载所有Chrome配置 用Chrom ...

  7. 黄聪:保持web页面生成的app一直处于用户登录状态不退出

    用户登录了会员中心,怎么保持登录状态! 由于封壳的内核及组件肯定没有浏览器APP应用那么强大,所以目前暂时的解决方案是: jquery.cookie.js  本文转载至:https://www.cnb ...

  8. Centos7 安装sz,rz命令

    yum install lrzsz 我记得以前某个我敬佩的人说过压缩分很多种,有空,补充这篇笔记.加油~

  9. 【springBoot】之配置文件application

    springboot使用一个全局的配置文件application.properties或者是application.yml,放在在src/main/recesources下或者在类路径下的/confi ...

  10. 【SpringBoot】支持Java1.6

    开发环境 Java 1.6; 需要修改的配置 指定java和tomcat版本 <!-- TO Support JDK 1.6 start --> <java.version>1 ...