Skip to content

Commit f61a59a

Browse files
committed
Atualizado url cadastro rs
1 parent 6cf1bae commit f61a59a

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

pynfe/processamento/comunicacao.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ def consulta_distribuicao(self, cnpj, nsu=0):
148148
pass
149149

150150
def consulta_cadastro(self, modelo, cnpj):
151+
# UF que utilizam a SVRS - Sefaz Virtual do RS: Para serviço de Consulta Cadastro: AC, RN, PB, SC
152+
lista_svrs = ['AC','RN','PB','SC']
151153
# RS implementa um método diferente na consulta de cadastro
152154
if self.uf.upper() == 'RS':
153155
url = NFE['RS']['CADASTRO']
154-
elif self.uf.upper() == 'SVRS':
156+
elif self.uf.upper() in lista_svrs:
155157
url = NFE['SVRS']['CADASTRO']
156158
elif self.uf.upper() == 'SVC-RS':
157159
url = NFE['SVC-RS']['CADASTRO']
@@ -295,13 +297,17 @@ def _get_url(self, modelo, consulta):
295297
# nfe Ex: https://nfe.fazenda.pr.gov.br/nfe/NFeStatusServico3
296298
self.url = NFE[self.uf.upper()][ambiente] + NFE[self.uf.upper()][consulta]
297299
elif modelo == 'nfce':
298-
# nfce Ex: https://homologacao.nfce.fazenda.pr.gov.br/nfce/NFeStatusServico3
299-
self.url = NFCE[self.uf.upper()][ambiente] + NFCE[self.uf.upper()][consulta]
300+
# PE é o unico UF que possiu NFE proprio e SVRS para NFCe
301+
if self.uf.upper() == 'PE':
302+
self.url = NFCE['SVRS'][ambiente] + NFCE['SVRS'][consulta]
303+
else:
304+
# nfce Ex: https://homologacao.nfce.fazenda.pr.gov.br/nfce/NFeStatusServico3
305+
self.url = NFCE[self.uf.upper()][ambiente] + NFCE[self.uf.upper()][consulta]
300306
else:
301307
raise Exception('Modelo não encontrado! Defina modelo="nfe" ou "nfce"')
302308
# Estados que utilizam outros ambientes
303309
else:
304-
lista_svrs = ['SE']
310+
lista_svrs = ['AC','RN','PB','SC','SE']
305311
if self.uf.upper() in lista_svrs:
306312
if self._ambiente == 1:
307313
ambiente = 'HTTPS'
@@ -410,13 +416,23 @@ def _post(self, url, xml):
410416
chave_cert = (cert, chave)
411417
# Abre a conexão HTTPS
412418
try:
413-
xml_declaration='<?xml version="1.0" encoding="utf-8"?>'
419+
xml_declaration='<?xml version="1.0" encoding="UTF-8"?>'
414420
# limpa xml com caracteres bugados para infNFeSupl em NFC-e
415421
xml = re.sub('<qrCode>(.*?)</qrCode>',
416422
lambda x:x.group(0).replace('&lt;','<').replace('&gt;','>').replace('amp;',''),
417423
etree.tostring(xml, encoding='unicode').replace('\n',''))
418424
xml = xml_declaration + xml
419425

426+
# adapter para substituir ssl por tls
427+
# s = requests.Session()
428+
# s.mount(url, AdapterTLSV1())
429+
# print(xml)
430+
# # print(self._post_header())
431+
# # Faz o request com o servidor
432+
# result = s.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False, timeout=120)
433+
# result.encoding = 'utf-8'
434+
# return result
435+
print(url)
420436
# Faz o request com o servidor
421437
result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False, timeout=120)
422438
result.encoding = 'utf-8'
@@ -649,3 +665,15 @@ def _post_https(self, url, xml, metodo):
649665
raise Exception('Método não implementado no autorizador.')
650666
except Exception as e:
651667
raise e
668+
669+
""" Adapter para conexão tls """
670+
from requests.adapters import HTTPAdapter
671+
from requests.packages.urllib3.poolmanager import PoolManager
672+
import ssl
673+
674+
class AdapterTLSV1(HTTPAdapter):
675+
def init_poolmanager(self, connections, maxsize, block=False):
676+
self.poolmanager = PoolManager(num_pools=connections,
677+
maxsize=maxsize,
678+
block=block,
679+
ssl_version=ssl.PROTOCOL_TLSv1_2)

pynfe/utils/webservices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
'CHAVE': 'sefazrs.rs.gov.br/ws/NfeConsulta/NfeConsulta2.asmx',
345345
'INUTILIZACAO': 'sefazrs.rs.gov.br/ws/nfeinutilizacao/nfeinutilizacao2.asmx',
346346
'EVENTOS': 'sefazrs.rs.gov.br/ws/recepcaoevento/recepcaoevento.asmx',
347-
'CADASTRO': 'sefazrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro2.asmx',
347+
'CADASTRO': 'https://cad.sefazrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro2.asmx',
348348
'DOWNLOAD': 'sefazrs.rs.gov.br/ws/nfeDownloadNF/nfeDownloadNF.asmx',
349349
'DESTINADAS': 'sefazrs.rs.gov.br/ws/nfeConsultaDest/nfeConsultaDest.asmx',
350350
'HTTPS': 'https://nfe.',

0 commit comments

Comments
 (0)