zoukankan      html  css  js  c++  java
  • python+requests发送post请求

    1、使用requests发送post请求

    # 导入request
    import requests
    
    # 接口地址
    url = 'http://v.juhe.cn/historyWeather/weather'
    # 发送的请求参数
    dd = {'city_id':'1154','key':'61e0c8a6d9614382afbaa7f35dbd3ec6','weather_date':'2020-7-15'}
    # 使用requests发送post请求
    re = requests.post(url,data=dd)
    # 定义js保存返回的json
    js = re.json()
    # 定义变量保存返回的参数
    a = js['reason']
    b = js['result']['city_name']
    c = js['error_code']
    # 打印返回的json,返回说明,错误码,城市名
    print('返回的json:',js,'
    返回说明:',a,'
    城市名',b,'
    错误码:',c)

    运行结果:

    返回的json: {'reason': '查询成功', 'result': {'city_id': '1154', 'city_name': '沭阳', 'weather_date': '2020-07-15', 'day_weather': '晴', 'night_weather': '阴', 'day_temp': '29℃', 'night_temp': '21℃', 'day_wind': '南风', 'day_wind_comp': '<3级', 'night_wind': '西南风', 'night_wind_comp': '<3级', 'day_weather_id': '00', 'night_weather_id': '02'}, 'error_code': 0}
    返回说明: 查询成功
    城市名 沭阳
    错误码: 0

    拿结果与接口文档对比即可

  • 相关阅读:
    浏览器版本过低
    虚拟PWN初探
    elasticsearch常用查询
    python安装pip模块
    spark-kafka-es交互 优化
    scala写文件
    python unittest
    scala collection(集合)
    spark-kafka-es交互
    scala语法
  • 原文地址:https://www.cnblogs.com/will-wu/p/13585176.html
Copyright © 2011-2022 走看看