from requests_toolbelt import MultipartEncoder import requests # from_data上传文件,注意参数名propertyMessageXml data = MultipartEncoder(fields={'propertyMessageXml': ('filename', open('D:/123.xml', 'rb'), 'text/xml')}) requests.post(url=url,data=data,headers={ 'Content-Type': data.content_type}) #raw上传文件 file = open('D:/123.xml','rb') requests.post(url=url,data=file.read(),headers={'Content-Type':'text/xml'}) #binary上传文件 files={'file':open('D:/123.xml','rb')} requests.post(url=url,files=files,headers={'Content-Type':'binary'})