zoukankan      html  css  js  c++  java
  • requests接口测试-天气预报api单参数

    接口地址:https://market.aliyun.com/products/57126001/cmapi014302.html?spm=5176.2020520132.101.11.7f0d7218veuaMm#sku=yuncode830200000

    # coding: utf-8
    import requests
    import json
    
    class web_requests(object):
        def __init__(self):
            pass
    
        def Interface(self, city):
            url = "http://jisutqybmf.market.alicloudapi.com/weather/query?city=%s" % city
            headers = {"Host": "jisutqybmf.market.alicloudapi.com",
                       "X-Ca-Timestamp": "1534950687019",
                       "gateway_channel": "http",
                       "X-Ca-Request-Mode": "debug",
                       "X-Ca-Key": "24955975",
                       "X-Ca-Stage": "RELEASE",
                       "Content-Type": "application/json;charset=utf-8",
                       "Authorization": "APPCODE 9c7eb663da9f4582a9d1a098c428d307"}
    
    
            r = requests.get(url=url, headers=headers)
            print(r.text)
            print(r.status_code)
            print(r.url)
    a = web_requests()
    a.Interface(input(">"))

    运行结果:

    D:pytestvenvScriptspython.exe D:/pytest/jiekou.py
    >上海
    {"status":"0","msg":"ok","result":{"city":"上海","cityid":"24","citycode":"101020100","date":"2018-08-22","week":"星期三","weather":"晴","temp":"28","temphigh":"33","templow":"27","img":"0","humidity":"80","pressure":"1000","windspeed":"3.0","winddirect":"静风","windpower":"0级","updatetime":"2018-08-22 22:40:00","index":[{"iname":"空调指数","ivalue":"部分时间开启","detail":"天气热,到中午的时候您将会感到有点热,因此建议在午后较热时开启制冷空调。"},{"iname":"运动指数","ivalue":"较适宜","detail":"天气较好,但因风力稍强,户外可选择对风力要求不高的运动,推荐您进行室内运动。"},{"iname":"紫外线指数","ivalue":"中等","detail":"属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。"},{"iname":"感冒指数","ivalue":"少发","detail":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。"},{"iname":"洗车指数","ivalue":"较不宜","detail":"较不宜洗车,未来一天无雨,风力较大,如果执意擦洗汽车,要做好蒙上污垢的心理准备。"},{"iname":"空气污染扩散指数","ivalue":"良","detail":"气象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。"},{"iname":"穿衣指数","ivalue":"炎热","detail":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫等清凉夏季服装。"}],"aqi":{"so2":"7","so224":"7","no2":"20","no224":"24","co":"0.690","co24":"0.520","o3":"98","o38":"93","o324":"95","pm10":"47","pm1024":"28","pm2_5":"26","pm2_524":"17","iso2":"6","ino2":"11","ico":"7","io3":"31","io38":"47","ipm10":"46","ipm2_5":"37","aqi":"47","primarypollutant":"O3","quality":"优","timepoint":"2018-08-22 22:00:00","aqiinfo":{"level":"一级","color":"#00e400","affect":"空气质量令人满意,基本无空气污染","measure":"各类人群可正常活动"}},"daily":[{"date":"2018-08-22","week":"星期三","sunrise":"05:23","sunset":"18:31","night":{"weather":"多云","templow":"27","img":"1","winddirect":"西北风","windpower":"4-5级"},"day":{"weather":"多云","temphigh":"33","img":"1","winddirect":"东北风","windpower":"4-5级"}},{"date":"2018-08-23","week":"星期四","sunrise":"05:23","sunset":"18:29","night":{"weather":"多云","templow":"26","img":"1","winddirect":"西北风","windpower":"3-5级"},"day":{"weather":"多云","temphigh":"33","img":"1","winddirect":"西北风","windpower":"4-5级"}},{"date":"2018-08-24","week":"星期五","sunrise":"05:24","sunset":"18:28","night":{"weather":"多云","templow":"25","img":"1","winddirect":"东北风","windpower":"3-5级"},"day":{"weather":"多云","temphigh":"31","img":"1","winddirect":"西北风","windpower":"3-5级"}},{"date":"2018-08-25","week":"星期六","sunrise":"05:25","sunset":"18:27","night":{"weather":"小雨","templow":"25","img":"7","winddirect":"东风","windpower":"微风"},"day":{"weather":"阵雨","temphigh":"29","img":"3","winddirect":"东北风","windpower":"3-5级"}},{"date":"2018-08-26","week":"星期日","sunrise":"05:25","sunset":"18:26","night":{"weather":"小雨","templow":"26","img":"7","winddirect":"东风","windpower":"微风"},"day":{"weather":"中雨","temphigh":"29","img":"8","winddirect":"东风","windpower":"微风"}},{"date":"2018-08-27","week":"星期一","sunrise":"05:26","sunset":"18:25","night":{"weather":"中雨","templow":"26","img":"8","winddirect":"东南风","windpower":"5-6级"},"day":{"weather":"中雨","temphigh":"30","img":"8","winddirect":"东南风","windpower":"4-5级"}},{"date":"2018-08-28","week":"星期二","sunrise":"05:26","sunset":"18:24","night":{"weather":"小雨","templow":"26","img":"7","winddirect":"东南风","windpower":"5-6级"},"day":{"weather":"小雨","temphigh":"29","img":"7","winddirect":"东南风","windpower":"5-6级"}}],"hourly":[{"time":"23:00","weather":"晴","temp":"28","img":"0"},{"time":"0:00","weather":"晴","temp":"28","img":"0"},{"time":"1:00","weather":"晴","temp":"28","img":"0"},{"time":"2:00","weather":"晴","temp":"28","img":"0"},{"time":"3:00","weather":"晴","temp":"28","img":"0"},{"time":"4:00","weather":"晴","temp":"27","img":"0"},{"time":"5:00","weather":"晴","temp":"27","img":"0"},{"time":"6:00","weather":"晴","temp":"27","img":"0"},{"time":"7:00","weather":"晴","temp":"28","img":"0"},{"time":"8:00","weather":"晴","temp":"29","img":"0"},{"time":"9:00","weather":"晴","temp":"30","img":"0"},{"time":"10:00","weather":"晴","temp":"31","img":"0"},{"time":"11:00","weather":"晴","temp":"32","img":"0"},{"time":"12:00","weather":"晴","temp":"32","img":"0"},{"time":"13:00","weather":"多云","temp":"33","img":"1"},{"time":"14:00","weather":"晴","temp":"33","img":"0"},{"time":"15:00","weather":"晴","temp":"32","img":"0"},{"time":"16:00","weather":"晴","temp":"32","img":"0"},{"time":"17:00","weather":"晴","temp":"31","img":"0"},{"time":"18:00","weather":"晴","temp":"30","img":"0"},{"time":"19:00","weather":"晴","temp":"30","img":"0"},{"time":"20:00","weather":"晴","temp":"29","img":"0"},{"time":"21:00","weather":"晴","temp":"28","img":"0"},{"time":"22:00","weather":"晴","temp":"28","img":"0"}]}}
    200
    http://jisutqybmf.market.alicloudapi.com/weather/query?city=%E4%B8%8A%E6%B5%B7

    遇到的问题:

    1. city后面用了%r,运行结果提示找不到城市

  • 相关阅读:
    eclipse快捷键
    iOS音频播放 (二):AudioSession 转
    HNU13377:Book Club(DFS)
    BAPC2014 K&&HUNNU11591:Key to Knowledge(中途相遇法)
    小米净水器与小区过滤价格水对照.xls
    NUTCH2.3 hadoop2.7.1 hbase1.0.1.1 solr5.2.1部署(一)
    hibernate动态表名映射--仅仅有想不到,没有做不到
    【BZOJ 1660】 [Usaco2006 Nov]Bad Hair Day 乱发节
    oracle-企业信息化
    线性查找算法
  • 原文地址:https://www.cnblogs.com/p36606jp/p/15113414.html
Copyright © 2011-2022 走看看