python自动化--request与curl的对应
概述 | curl | python |
data-urlencode 转为列表内元组,作为params发送 | curl --location 'https://xxxxx' --header 'cookie: t=xxx' --header 'Content-Type: application/x-www-form-urlencoded' --data-urlencode 'a=1' --data-urlencode 'b=2' | params = [('a', '1'),('b', '2')] res = requests.post(url, params=list(eval(params), headers=headers) |
form 借助MultipartEncoder | curl --location 'https://xxxx' --header 'cookie: t=xxx' --form 'a="1"' --form 'b="2"' | from requests_toolbelt.multipart.encoder import MultipartEncoder data = MultipartEncoder({'a': '1','b': '2'}) headers['Content-Type'] = data.content_type res = requests.post(url, data=data, headers=headers) |
python自动化 文章被收录于专栏
python写好pytest自动化的一些小妙招