python第六课
第六课:from urllib import requestfrom urllib import parseimport jsonimport requests------urllib-------# get请求方式url = 'http://api.nnzhp.cn/api/user/stu_info'data = {"stu_name":"xiaohei"}tmpdate = parse.urlencode(data) #将数据变换为KV K=vprint(tmpdate)# 接口 + 参数tmpurl = url + '?' + tmpdate #接口和参数拼接res = request.urlopen(tmpurl) #请求接口resForRead = res.read().decode() #通过read方法获取返回值结果,返回值结果是bytes;通过decode将bytes转换成字符串resFORDict = json.loads(resForRead) #通过json将字符串转换为字典print(resForRead)print(resFORDict)# post请求方式url = "http://api.nnzhp.cn/api/user/login"date = {"username":"niuhanyang","passwd":"aA123456"