mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.88k stars 583 forks source link

SOAP MTOM Attachment #781

Open fedale opened 6 years ago

fedale commented 6 years ago

I have this WSDL https://service.pmpay.it/payPA/services/PayPA?wsdl When call operation "PagamentoEsistenteBollettino" fromZeep it returns something like that, only if I set raw_response:

HTTP/1.1 200 OK Content-Type: multipart/related; type="text/xml"; start=""; boundary="----=_Part_187_56733036.1531119409567" Date: Mon, 09 Jul 2018 06:56:48 GMT Server: Apache/2.2.34 (Amazon) Set-Cookie: JSESSIONID=071051776929F840961967409854D3CA; Path=/payPA/; HttpOnly transfer-encoding: chunked Connection: keep-alive

------=_Part_187_56733036.1531119409567 Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: binary Content-Id:

<?xml version="1.0" encoding="UTF-8"?>OK</soapenv:Body></soapenv:Envelope> ------=_Part_187_56733036.1531119409567 Content-Type: application/octet-stream Content-Transfer-Encoding: binary Content-Id: <26B914A4F97C0F965EB14E2AF41B4BEF>

%PDF-1.5 %âãÏÓ 6 0 obj <</Length 2328/Filter/FlateDecode>>stream ôlžUÿÍN h”-YÜyª9;8e+`óæ¾ÏxtÝiä} èG/ðd×-k½?00l6Ðúu]gèÃþ ú n²¯1?Øâ7ù hJz w&IKùë

[...SNIP...]

Without "raw_response", it will return a NoneType, generating a parse error.

Is there a way to manage this type of response with Zeep?

Thanks in advance Danilo DI Moia

Eveler commented 5 years ago

I saw URL-encoded attachment id in some cases. The raw response. And, of course, I got parse error.

This patch resolves the problem: (link) `Index: zeep/wsdl/messages/xop.py IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8

--- zeep/wsdl/messages/xop.py (date 1539132819497) +++ zeep/wsdl/messages/xop.py (date 1539132819497) @@ -1,4 +1,5 @@ import base64 +from urllib.parse import unquote

def process_xop(document, message_pack): @@ -11,12 +12,14 @@

 for xop_node in xop_nodes:
     href = xop_node.get('href')
mrcoolhp commented 5 years ago

I am also facing same issue where my SOAP response contains XML + Binary, Will this patch resolve this issue so that it will extract the attachment

tcvieira commented 5 years ago

I saw URL-encoded attachment id in some cases. The raw response. And, of course, I got parse error.

This patch resolves the problem: (link)

`Index: zeep/wsdl/messages/xop.py IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 --- zeep/wsdl/messages/xop.py (date 1539132819497) +++ zeep/wsdl/messages/xop.py (date 1539132819497) @@ -1,4 +1,5 @@ import base64 +from urllib.parse import unquote

def process_xop(document, message_pack): @@ -11,12 +12,14 @@

 for xop_node in xop_nodes:
     href = xop_node.get('href')
  •  href = unquote(href)
     if href.startswith('cid:'):
         href = '<%s>' % href[4:]
    
     value = message_pack.get_by_content_id(href)
     if not value:
  •      raise ValueError("No part found for: %r" % xop_node.get('href'))
  •      raise ValueError("No part found for: %r" % unquote(
  •          xop_node.get('href')))
     num_replaced += 1
    
     xop_parent = xop_node.getparent()

`

It fixed the problem for me! Thanks!