python--requests模块、深拷贝、浅拷贝
requests模块
requests模块是基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库。它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTTP测试需求。
可通过【pip install requests】来安装。
具体使用见下面例子
1 import requests 2 import json 3 4 url='xxx' 5 #get请求 6 res1 = requests.get(url).text #返回字符串 7 res2 = requests.get(url).json() #返回json串 8 9 #post请求,直接拼接参数 10 d = { 11 "site":"xxx", 12 "url":"http://xxx" 13 } 14 res3 = requests.post(url).text #拼接方式传参,返回字符串 15 res4 = requests.post(url,json=d).json() #json方式传参 16 17 # 获取cookies 18 cookie_url = 'http://127.0.0.1:8888/set_cookies' 19 date = {"userid":1,"money":55} 20 cookie = {'token':"122334"} 21 res = requests.post(cookie_url,json=date,cookies=cookie).json() 22 print(res) 23 24 # 获取header 25 header_url = 'http://127.0.0.1:8888/set_header' 26 date = {"userid":1} 27 header = {'Content-Type':"application/json"} 28 res = requests.post(header_url,json=date,headers=header).json() 29 print(res)
深拷贝、浅拷贝
浅拷贝相当于新建一个快捷方式,可变变量的等号【=】就是浅拷贝
深拷贝分为copy.deepcopy(lis)和copy.copy(lis)两种
copy.deepcopy(lis) 相当于复制了一份
copy.copy(lis) 相当于拷贝了一个对象,但对象属性还是引用原来的
下面是copy.deepcopy(lis)的例子
1 import copy 2 lis =[1,1,2,3,4,5,6] 3 lis2 = copy.deepcopy(lis) 4 for n in lis2: 5 if n%2!=0: 6 lis.remove(n) 7 print(lis)
加盐
加盐就是加入一串新的字符串,以增加密码复杂度,一起进行加密,这个字符串就是盐值。