You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Junior Tada edited this page Jan 31, 2020
·
7 revisions
Exemplo de como consultar o status do serviço, NFe ou NFCe.
frompynfe.processamento.comunicacaoimportComunicacaoSefazfrompynfe.utils.flagsimportNAMESPACE_NFEfromlxmlimportetreecertificado="/home/user/certificado.pfx"senha='senha'uf='pr'homologacao=Truecon=ComunicacaoSefaz(uf, certificado, senha, homologacao)
xml=con.status_servico('nfe') # nfe ou nfceprint (xml.text)
# exemplo de leitura da respostans= {'ns': NAMESPACE_NFE }
# algumas uf podem ser xml.text ou xml.contentresposta=etree.fromstring(xml.content)[0][0]
status=resposta.xpath('ns:retConsStatServ/ns:cStat',namespaces=ns)[0].textmotivo=resposta.xpath('ns:retConsStatServ/ns:xMotivo',namespaces=ns)[0].textprint(status)
print(motivo)
Em algumas UFs o formato do xml de resposta pode variar, para ver a resposta tente: