我正在尝试使用Python发送带有多个附件的SOAP请求,但是会引发错误。
#!/usr/bin/env python3
import requests
url="http://server002:8080/jservicejaxws/job?wsdl"
imageFileName = 'image.jpg'
imageFilePath = '/tmp/output/' + imageFileName
xmlFileName = 'data.xml'
xmlFilePath = '/tmp/output/' + xmlFileName
headers = {'content-type': 'Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="application/soap+xml"; action=""; boundary="----=_Part_5_1721772104.1566219504205"'}
body = """<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:ser="http://server.ws.service.company.com/">
<soap:Header/>
<soap:Body>
<ser:doStuff>
<arg0>my information</arg0>
</ser:doStuff>
</soap:Body>
</soap:Envelope>"""
encoded_request = body.encode('utf-8')
multiple_files = [
('image', (imageFileName, open(imageFilePath, 'rb'), 'image/jpeg')),
('document', (xmlFileName, open(xmlFilePath, 'rb'), 'application/octet-stream'))]
response = requests.post(url,data=encoded_request,headers=headers, files=multiple_files)
print('Done')
显示此错误...
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 122, in _encode_files
raise ValueError("Data must not be a string.")
ValueError: Data must not be a string.
尝试发送不带数据部分(信封)的请求不会产生任何错误...如何发送带有信封和多个附件的Soap请求?