Python中将字典格式拼接到get请求参数中

  def myWeather(self):
        
        data = {
            "appid": "42928933",
            "appsecret": "Qtgjo71E",
            "cityid":"",
            "city": "北京",
            "ip": "",
            "callback": "",
            "vue": "1",
            "unescape": "1"
        }

        mylist = []
        for key in data.items():
            my = "=".join(key)
            mylist.append(my)

        params = "&".join(mylist)

        url = 'https://www.tianqiapi.com/free/day?appid=42928933&appsecret=Qtgjo71E&unescape=1&'+params
        req = requests.get(url=url).json()
        return req

params的输出结果:appid=42928933&appsecret=Qtgjo71E&cityid=&city=北京&ip=&callback=&vue=1&unescape=1

上一篇:Java练习题1


下一篇:PTA 7-5 带密码的约瑟夫问题