-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.py
More file actions
49 lines (43 loc) · 1.57 KB
/
Copy pathstatus.py
File metadata and controls
49 lines (43 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import configparser
from lxml import etree
from pynfe.processamento.comunicacao import ComunicacaoSefaz
def status(modelo):
try:
con = ComunicacaoSefaz(UF, CERT, SENHA, homologacao)
xml = con.status_servico(modelo)
return xml
except Exception:
print('Erro comunicando com Servidor')
return None
def mostra(ret):
print(ret.content)
root = etree.fromstring(ret.content)
elemento = root[0][0][0]
ns = {'ns':'http://www.portalfiscal.inf.br/nfe'}
cstat = elemento.xpath('ns:cStat', namespaces=ns)[0].text
tpamb = elemento.xpath('ns:tpAmb', namespaces=ns)[0].text
veraplic = elemento.xpath('ns:verAplic', namespaces=ns)[0].text
xmotivo = elemento.xpath('ns:xMotivo', namespaces=ns)[0].text
cuf = elemento.xpath('ns:cUF', namespaces=ns)[0].text
dhrecbto = elemento.xpath('ns:dhRecbto', namespaces=ns)[0].text
print(cuf)
print(tpamb)
print(veraplic)
print(cstat)
print(xmotivo)
print(dhrecbto)
if __name__ == '__main__':
cfg = configparser.ConfigParser()
cfg.read('config.ini')
CERT = cfg.get("geral","cert_pfx")
SENHA = cfg.get("geral","cert_pwd")
UF = 'PR'
homologacao = False
ret_nfe = status('nfe')
ret_nfce = status('nfce')
if ret_nfe is not None:
print('\nStatus da Sefaz - NF-e:')
mostra(ret_nfe)
if ret_nfce is not None:
print('\nStatus da Sefaz - NFC-e:')
mostra(ret_nfce)