From 582742ecca75c8e3d097c02bf288552eca5199d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Luna?= Date: Fri, 3 Nov 2017 12:14:40 -0200 Subject: [PATCH] =?UTF-8?q?[FIX]=20Corrige=20consulta=20de=20distribu?= =?UTF-8?q?=C3=AD=C3=A7=C3=A3o=20de=20NF-e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytrustnfe/client.py | 12 +++++++++--- pytrustnfe/nfe/comunicacao.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pytrustnfe/client.py b/pytrustnfe/client.py index 30047d1..03adbd2 100644 --- a/pytrustnfe/client.py +++ b/pytrustnfe/client.py @@ -42,14 +42,20 @@ class HttpClient(object): self.cert_path = cert_path self.key_path = key_path - def _headers(self, action): + def _headers(self, action, send_raw): + if send_raw: + return { + 'Content-type': 'text/xml; charset=utf-8; action="http://www.portalfiscal.inf.br/nfe/wsdl/%s"' % action, + 'Accept': 'application/soap+xml; charset=utf-8', + } + return { 'Content-type': 'application/soap+xml; charset=utf-8; action="http://www.portalfiscal.inf.br/nfe/wsdl/%s"' % action, 'Accept': 'application/soap+xml; charset=utf-8', } - def post_soap(self, xml_soap, cabecalho): - header = self._headers(cabecalho.soap_action) + def post_soap(self, xml_soap, cabecalho, send_raw): + header = self._headers(cabecalho.soap_action, send_raw) urllib3.disable_warnings(category=InsecureRequestWarning) res = requests.post(self.url, data=xml_soap, cert=(self.cert_path, self.key_path), diff --git a/pytrustnfe/nfe/comunicacao.py b/pytrustnfe/nfe/comunicacao.py index 08a7a6a..df6ba53 100644 --- a/pytrustnfe/nfe/comunicacao.py +++ b/pytrustnfe/nfe/comunicacao.py @@ -30,5 +30,5 @@ def executar_consulta(certificado, url, cabecalho, xmlEnviar, send_raw=False): if send_raw: xml = '' + xmlEnviar.rstrip('\n') xml_enviar = xml - xml_retorno = client.post_soap(xml_enviar, cabecalho) + xml_retorno = client.post_soap(xml_enviar, cabecalho, send_raw) return sanitize_response(xml_retorno.encode())