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
标签:mylist,Qtgjo71E,get,Python,url,拼接,params,unescape,42928933 来源: https://www.cnblogs.com/tianpin/p/15435280.html