'Expected “xref” keyword or xref stream object (line=9351, col=44, token=‘ilter’)

I got weird error like this

Expected “xref” keyword or xref stream object (line=9351, col=44, token=‘ilter’)

I'm trying to fill keys in a pdf via python using 'pdfrw' library. What I'm trying to do is this

for page in template_pdf.pages:
        annotations = page[ANNOT_KEY]
        if annotations:
            for annotation in annotations:
                if (
                    annotation[SUBTYPE_KEY] == WIDGET_SUBTYPE_KEY
                    and annotation[ANNOT_FIELD_KEY]
                ):
                    key = annotation[ANNOT_FIELD_KEY][1:-1]
                    if key in data_dict.keys():
                        if type(data_dict[key]) is bool:
                            if data_dict[key] is True:
                                annotation.update(
                                    pdfrw.PdfDict(AS=pdfrw.PdfName("Yes"))
                                )
                        else:
                            annotation.update(
                                pdfrw.PdfDict(V="{}".format(data_dict[key]))
                            )
                            annotation.update(pdfrw.PdfDict(AP=""))
            template_pdf.Root.AcroForm.update(
                pdfrw.PdfDict(NeedAppearances=pdfrw.PdfObject("true"))
            )
            name_of_document = "%s.%s" % (
                uuid.uuid4(),
                output_pdf_path.split(".")[-1],
            )
            output_pdf_path = os.path.join("media/uploads", name_of_document)
            pdfrw.PdfWriter().write(output_pdf_path, template_pdf)
            title = input_pdf_path[
                input_pdf_path.rfind("/") + 1 : len(input_pdf_path)
            ]

To clarify, this code works locally but in production no

Can someone help me please?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source