Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erro: xsdata.exceptions.ParserError: Failed to create target class `` #113

Open
ismaelnjr opened this issue Jul 19, 2024 · 5 comments
Open

Comments

@ismaelnjr
Copy link

Estou iniciando em python e estou tendo o seguinte erro que não consegui resolver. Fiz o seguinte código para ler o CNPJ de um xml:

from nfelib.nfe.bindings.v4_0.proc_nfe_v4_00 import NfeProc

nfe_proc = NfeProc.from_xml("etc/xml/35240406313527000152550010000688311001248352-nfe.xml")

print(nfe_proc.NFe.infNFe.emit.CNPJ)

e ao executar estou tendo o seguinte erro:

Traceback (most recent call last):
File "c:\Users\Dell\OneDrive\vs_code\projetos\nfelib-test\nfe-test2.py", line 3, in
nfe_proc = NfeProc.from_xml("nfelib/nfe/samples/v4_0/leiauteNFe/NFe35200159594315000157550010000000012062777161.xml")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\OneDrive\vs_code\projetos\nfelib-test.venv\Lib\site-packages\nfelib_init_.py", line 30, in
from_xml
return XmlParser().from_string(xml)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\OneDrive\vs_code\projetos\nfelib-test.venv\Lib\site-packages\xsdata\formats\dataclass\parsers\mixins.py", line 67, in from_string
return self.from_bytes(source.encode(), clazz, ns_map)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\OneDrive\vs_code\projetos\nfelib-test.venv\Lib\site-packages\xsdata\formats\dataclass\parsers\mixins.py", line 88, in from_bytes
return self.parse(io.BytesIO(source), clazz, ns_map)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\OneDrive\vs_code\projetos\nfelib-test.venv\Lib\site-packages\xsdata\formats\dataclass\parsers\bases.py", line 67, in parse
raise ParserError(f"Failed to create target class {target_class}")

O que devo fazer para corrigir isso?

@antoniospneto
Copy link
Contributor

Penso que o erro está aqui:

nfe_proc = NfeProc.from_xml("etc/xml/35240406313527000152550010000688311001248352-nfe.xml")

se vc tá passando um caminho deveria usar from_path não from_xml.
no from_xml vc tem que passar o conteudo do xml em string.

@ismaelnjr
Copy link
Author

Eu troquei para from_path, e o erro continua infelizmente.

@antoniospneto
Copy link
Contributor

antoniospneto commented Jul 19, 2024

Eu troquei para from_path, e o erro continua infelizmente.

Mesmo erro? será que o caminho do path tá correto mesmo?
faça o debug do método from_path dentro do nfelib para verificar se o conteudo do xml tá sendo carregado corretamente.

@ismaelnjr
Copy link
Author

seu eu rodo desta forma funciona:

from nfelib.nfe.bindings.v4_0 import NfeProc
from xsdata.formats.dataclass.parsers import XmlParser

parser = XmlParser()
nfeProc = parser.parse("etc//xml//35240406313527000152550010000688321001248368-nfe.xml", NfeProc)
print(nfeProc.NFe.infNFe.emit.CNPJ)

Me parece que a chamada do from_path não encontra as classes para instanciar

@antoniospneto
Copy link
Contributor

@ismaelnjr boa, ia te sugerir olhar como está sendo feito nas classes de testes.

@rvalyi a documentação no readme tá desatualziado será?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants