akretion / factur-x

Python lib for Factur-X, the e-invoicing standard for France and Germany
Other
170 stars 56 forks source link

lxml issue, cannot import etree #35

Closed Wizyma closed 1 year ago

Wizyma commented 1 year ago

Hello 👋
So first of all thanks a lot for this lib, it is super usefull ! I got it working at some point and now i am trying to use it in a AWS env, but every time i have an error saying

cannot import name 'etree' from 'lxml' (/var/task/lxml/__init__.py)

Which is quite weird, i inspected the zip that is deployed for my lambda, lxml is in it. I am not a python expert, and i am struggling a lot with it, if someone had this issue before or knows about it i would love some help or some insights ! Thanks you !

Env

Serverless v3 runtime: python 3.8 (also tried with 3.9)

The actuel code (removed irrelevant line)

import json

import os
import io
import tempfile

from facturx import generate_from_file

def generate_factur_x(pdf_data, xml_data):
    pdf_file = io.BytesIO(pdf_data)
    xml_file = io.BytesIO(xml_data)

    # Create a temporary file to store the generated PDF content
    with tempfile.NamedTemporaryFile(delete=False) as temp_pdf_file:
        generate_from_file(pdf_file, xml_file, 'factur-x',
                           output_pdf_file=temp_pdf_file.name)

        # Read the generated PDF content from the temporary file
        temp_pdf_file.seek(0)
        generated_pdf_content = temp_pdf_file.read()

    # Clean up the temporary file
    temp_pdf_file.close()
    temp_pdf_path = temp_pdf_file.name
    return generated_pdf_content, temp_pdf_path
Wizyma commented 1 year ago

Hi again 👋
Actually resolved it in the end, if anyone come accross this, using an docker image to build the lxml binary for your lambda resolve this issue. Closing it !