Python 使用requests模块发送GET和POST请求的实现代码

yipeiwu_com6年前Python基础

①GET

# -*- coding:utf-8 -*-

import requests

def get(url, datas=None):
  response = requests.get(url, params=datas)
  json = response.json()
  return json

注:参数datas为json格式

②POST

# -*- coding:utf-8 -*-

import requests

def post(url, datas=None):
  response = requests.post(url, data=datas)
  json = response.json()
  return json

注:参数datas为json格式

相关文章

python通过ffmgep从视频中抽帧的方法

如下所示: ffmpeg中文文档:http://linux.51yip.com/search/ffmpeg ffmpeg -i test_baofeng.wmv -y -f image2...

python 中文乱码问题深入分析

python 中文乱码问题深入分析

在本文中,以'哈'来解释作示例解释所有的问题,“哈”的各种编码如下: 1. UNICODE (UTF8-16),C854; 2. UTF-8,E59388; 3. GBK,B9FE。 一...

Linux环境下MySQL-python安装过程分享

1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本   python -V   检查python版本 2. 安装mysql...

Python 移动光标位置的方法

如下所示: x = file('1.txt','r') print x.tell() #显示当前光标位置 x.seek(3) print x.tell() #没有设置光标位置,...

python 设置输出图像的像素大小方法

如下所示: plt.rcParams['savefig.dpi'] = 300 #图片像素 plt.rcParams['figure.dpi'] = 300 #分辨率 为了记住不...