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

KeyError: 'Curp' #26

Open
arielmol opened this issue Aug 27, 2024 · 4 comments
Open

KeyError: 'Curp' #26

arielmol opened this issue Aug 27, 2024 · 4 comments

Comments

@arielmol
Copy link

arielmol commented Aug 27, 2024

Extrañamente usando la versión de git instalando:

commit ea86c7fd35e76b9b9893beb395296313cb99fab7 (HEAD -> main, tag: 4.5.6, origin/main, origin/HEAD)
Author: SatCFDI <satcfdi@outlook.com>
Date:   Tue Aug 13 18:05:20 2024 -0600

    Added check_same_thread=False

En algunos servers sale lo siguiente:

[ERROR] KeyError: 'Curp'
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 79, in lambda_handler
    cfdi = CFDI.from_string(xmldata)
  File "/opt/python/lib/python3.12/site-packages/satcfdi/xelement.py", line 61, in from_string
    return cls.from_xml(etree.fromstring(string, parser=parser))
  File "/opt/python/lib/python3.12/site-packages/satcfdi/xelement.py", line 49, in from_xml
    obj = cfdi_objectify[xml_root.tag](cls, xml_root)
  File "/opt/python/lib/python3.12/site-packages/satcfdi/transform/objectify.py", line 14769, in s_comprobante0
    return comprobante1(cls, node)
  File "/opt/python/lib/python3.12/site-packages/satcfdi/transform/objectify.py", line 10184, in comprobante1
    self['Complemento'] = complemento3(cls, el)
  File "/opt/python/lib/python3.12/site-packages/satcfdi/transform/objectify.py", line 10349, in complemento3
    self = {n.tag.rsplit('}', 1)[-1]: cfdi_objectify.get(n.tag, default_objectify)(cls, n) for n in node}
  File "/opt/python/lib/python3.12/site-packages/satcfdi/transform/objectify.py", line 14909, in s_nomina1
    return nomina1(cls, node)
  File "/opt/python/lib/python3.12/site-packages/satcfdi/transform/objectify.py", line 13981, in nomina1
    self['Receptor'] = receptor9(cls, el)
  File "/opt/python/lib/python3.12/site-packages/satcfdi/transform/objectify.py", line 14030, in receptor9
    self['Curp'] = node.attrib['Curp']
  File "src/lxml/etree.pyx", line 2545, in lxml.etree._Attrib.__getitem__

Lo raro es que pareciera depender del server, no he podido validar uno por uno la version de satcfdi pero dos son de main.

Y el CFDI es un CFDI de nomina que si tiene la CURP ya que en mi maquina local valida correctamente.

En el que sí valida use:

$ pip freeze
arrow @ file:///home/conda/feedstock_root/build_artifacts/arrow_1696128962909/work
beautifulsoup4==4.12.3
Brotli @ file:///home/conda/feedstock_root/build_artifacts/brotli-split_1695989787169/work
certifi @ file:///home/conda/feedstock_root/build_artifacts/certifi_1720457958366/work/certifi
cffi @ file:///home/conda/feedstock_root/build_artifacts/cffi_1723018375539/work
charset-normalizer @ file:///home/conda/feedstock_root/build_artifacts/charset-normalizer_1698833585322/work
cryptography==42.0.8
cssselect2==0.7.0
distlib==0.3.8
filelock==3.15.4
fonttools==4.53.1
h2 @ file:///home/conda/feedstock_root/build_artifacts/h2_1634280454336/work
hpack==4.0.0
html5lib==1.1
hyperframe @ file:///home/conda/feedstock_root/build_artifacts/hyperframe_1619110129307/work
idna @ file:///home/conda/feedstock_root/build_artifacts/idna_1724450538981/work
Jinja2==3.1.4
lxml==5.3.0
MarkupSafe==2.1.5
packaging==24.1
pillow==10.4.0
platformdirs==4.2.2
pycparser @ file:///home/conda/feedstock_root/build_artifacts/pycparser_1711811537435/work
pydyf==0.11.0
pyOpenSSL==24.2.1
pyphen==0.16.0
pypng==0.20220715.0
PySocks @ file:///home/conda/feedstock_root/build_artifacts/pysocks_1661604839144/work
python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/python-dateutil_1709299778482/work
pytz==2024.1
qrcode==7.4.2
requests @ file:///home/conda/feedstock_root/build_artifacts/requests_1717057054362/work
satcfdi @ file:///home/ariel/projects/python-satcfdi
setuptools==72.2.0
six @ file:///home/conda/feedstock_root/build_artifacts/six_1620240208055/work
soupsieve==2.6
tabulate==0.9.0
tinycss2==1.3.0
types-python-dateutil @ file:///home/conda/feedstock_root/build_artifacts/types-python-dateutil_1724221107168/work
typing_extensions==4.12.2
urllib3 @ file:///home/conda/feedstock_root/build_artifacts/urllib3_1719391292974/work
virtualenv==20.26.3
weasyprint==62.3
webencodings==0.5.1
wheel==0.44.0
XlsxWriter==3.2.0
zopfli==0.2.3
zstandard==0.23.0
@arielmol
Copy link
Author

arielmol commented Aug 27, 2024

Al parecer esto tiene que ver con el encoding, he encontrado una variedad de encodings del sat.

  #  - XML 1.0 document, UTF-8 Unicode (with BOM) text, with very long lines, with no line terminators
  #  - XML 1.0 document, UTF-8 Unicode (with BOM) text, with very long lines
  #  - UTF-8 Unicode text, with very long lines
  #  - UTF-8 Unicode text, with very long lines, with no line terminators
  #  - ASCII text, with very long lines

Y eso en las descargas directas del SAT e incluso descargas de varios PACs

@satcfdi
Copy link
Member

satcfdi commented Sep 11, 2024

Ese error ocurre por que el campo de curp es requerido, se podria en teoria relajar un poco las validaciones para permitir que los campos sean opcionales

@arielmol
Copy link
Author

No, ocurre porque el XML esta en otro encoding, el SAT aunque hagas descargas masivas te manda esos:

  #  - XML 1.0 document, UTF-8 Unicode (with BOM) text, with very long lines, with no line terminators
  #  - XML 1.0 document, UTF-8 Unicode (with BOM) text, with very long lines
  #  - UTF-8 Unicode text, with very long lines
  #  - UTF-8 Unicode text, with very long lines, with no line terminators
  #  - ASCII text, with very long lines

@satcfdi
Copy link
Member

satcfdi commented Oct 9, 2024

tienes un ejemplo de una factura que este fallando? para poder replicar el error

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