类库安装路径:python36/lib/site-package/requests
header需要加的
1. url-encode 2. json 3. xml 4.html
5、file 不要加
#3 form
# host = ‘http://ws.webxml.com.cn‘
# headers = {"Content-Type": "application/x-www-form-urlencoded"}
# r = requests.post(url=host + ‘/WebServices/WeatherWS.asmx/getSupportCityString‘,
# headers=headers, data={"theRegionCode": 311101})
# print(r.text)
#4 xml java .net
# host = ‘http://ws.webxml.com.cn‘
# headers = {"Content-Type": "text/xml; charset=utf-8", "SOAPAction": "http://WebXml.com.cn/getSupportCityString"}
# xml = ‘‘‘<?xml version="1.0" encoding="utf-8"?>
# <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
# <soap:Body>
# <getSupportCityString xmlns="http://WebXml.com.cn/">
# <theRegionCode>311101</theRegionCode>
# </getSupportCityString>
# </soap:Body>
# </soap:Envelope>‘‘‘
#
# r = requests.post(url=host + ‘/WebServices/WeatherWS.asmx‘,
# headers=headers, data=xml)
# print(r.text)
#5 json data=json字符串 如果不用引号需要先转成字符串, json=字典
headers = {"Content-Type": "application/json; charset=utf-8"}
r = requests.post(url=‘http://139.199.132.220:8000/event/weather/getWeather/‘, headers=headers,
data=‘{"theCityCode": 1}‘)
r2 = requests.post(url=‘http://139.199.132.220:8000/event/weather/getWeather/‘, headers=headers,
json={"theCityCode": 1})
print(r.text)
print(r2.text)
requets库下载实现
import requests
header ={‘Cookie‘: ‘uid=1; token=44c972f05d76fdd93c31f9c2b65bb098f308cdfc‘}
url =‘http://118.24.91.97:9000/api/export/?month=1&city=110000‘
res = requests.get(url=url,headers=header)
#res.raw
with open(‘./result.csv‘, ‘wb‘) as fd:
for text in res.iter_content(1024):
fd.write(text)
requests库 session的使用:
系统环境变量path种配置allure
allure --version