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