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 ldap实现登录实例代码

下面一段代码是小编给大家介绍的Python ldap实现登录实例代码,一起看看吧 ldap_config = { 'ldap_path': 'ldap://xx.xx.xx.xx...

Python实现程序判断季节的代码示例

Python实现程序判断季节的代码示例

1.用户输入月份,判断这个月是哪个季节 month = int(input('Month:')) if month in [3,4,5]: print('春季') elif mo...

python实时监控cpu小工具

python实时监控cpu小工具

本文实例为大家分享了python实时监控cpu的工具,供大家参考,具体内容如下 虽然写的很不完善,但是当练手吧,对于实时监控cpu还是有点用处的,虽然android studio已经提供...

python生成词云的实现方法(推荐)

python生成词云的实现方法(推荐)

期末复习比较忙过段时间来专门写scrapy框架使用,今天介绍如何用python生成词云,虽然网上有很多词云生成工具,不过自己用python来写是不是更有成就感。 今天要生成的是励志歌曲的...

浅谈python的输入输出,注释,基本数据类型

1.输入与输出 python中输入与输出函数为:print、input help() 帮助的使用:help() help(print) print(value, ..., sep=...