kotify / cloud-print-utils

AWS Lambda functions to generate pdf files and images
MIT License
110 stars 33 forks source link

AWS Lambda with python 12 #24

Closed sks-keo closed 6 months ago

sks-keo commented 7 months ago

I have follow this step:

WeasyPrint is python based pdf/png print service.

Run make build/weasyprint-layer-python3.12.zip to build a layer, for details and docker lambda example see related readme.

Response
{
  "errorMessage": "cannot load library 'pango-1.0-0': pango-1.0-0: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0-0'",
  "errorType": "OSError",
  "requestId": "",
  "stackTrace": [
    "  File \"/var/lang/lib/python3.12/importlib/__init__.py\", line 90, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n",
    "  File \"<frozen importlib._bootstrap>\", line 1387, in _gcd_import\n",
    "  File \"<frozen importlib._bootstrap>\", line 1360, in _find_and_load\n",
    "  File \"<frozen importlib._bootstrap>\", line 1331, in _find_and_load_unlocked\n",
    "  File \"<frozen importlib._bootstrap>\", line 935, in _load_unlocked\n",
    "  File \"<frozen importlib._bootstrap_external>\", line 994, in exec_module\n",
    "  File \"<frozen importlib._bootstrap>\", line 488, in _call_with_frames_removed\n",
    "  File \"/var/task/app/main.py\", line 1, in <module>\n    from weasyprint import CSS, HTML\n",
    "  File \"/opt/python/weasyprint/__init__.py\", line 419, in <module>\n    from .css import preprocess_stylesheet  # noqa isort:skip\n",
    "  File \"/opt/python/weasyprint/css/__init__.py\", line 27, in <module>\n    from .computed_values import COMPUTER_FUNCTIONS\n",
    "  File \"/opt/python/weasyprint/css/computed_values.py\", line 9, in <module>\n    from ..text.ffi import ffi, pango, units_to_double\n",
    "  File \"/opt/python/weasyprint/text/ffi.py\", line 431, in <module>\n    pango = _dlopen(\n",
    "  File \"/opt/python/weasyprint/text/ffi.py\", line 417, in _dlopen\n    return ffi.dlopen(names[0])  # pragma: no cover\n",
    "  File \"/opt/python/cffi/api.py\", line 150, in dlopen\n    lib, function_cache = _make_ffi_library(self, name, flags)\n",
    "  File \"/opt/python/cffi/api.py\", line 832, in _make_ffi_library\n    backendlib = _load_backend_lib(backend, libname, flags)\n",
    "  File \"/opt/python/cffi/api.py\", line 827, in _load_backend_lib\n    raise OSError(msg)\n"
  ]
}

Function Logs
ine 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/var/task/app/main.py", line 1, in <module>
    from weasyprint import CSS, HTML
  File "/opt/python/weasyprint/__init__.py", line 419, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "/opt/python/weasyprint/css/__init__.py", line 27, in <module>
    from .computed_values import COMPUTER_FUNCTIONS
  File "/opt/python/weasyprint/css/computed_values.py", line 9, in <module>
    from ..text.ffi import ffi, pango, units_to_double
  File "/opt/python/weasyprint/text/ffi.py", line 431, in <module>
    pango = _dlopen(
  File "/opt/python/weasyprint/text/ffi.py", line 417, in _dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/opt/python/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/opt/python/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/opt/python/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)INIT_REPORT Init Duration: 609.44 ms  Phase: init Status: error   Error Type: Runtime.ExitError
-----
WeasyPrint could not import some external libraries. Please carefully follow the installation steps before reporting an issue:
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#troubleshooting 
-----
[ERROR] OSError: cannot load library 'pango-1.0-0': pango-1.0-0: cannot open shared object file: No such file or directory.  Additionally, ctypes.util.find_library() did not manage to locate a library called 'pango-1.0-0'
Traceback (most recent call last):
  File "/var/lang/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/var/task/app/main.py", line 1, in <module>
    from weasyprint import CSS, HTML
  File "/opt/python/weasyprint/__init__.py", line 419, in <module>
    from .css import preprocess_stylesheet  # noqa isort:skip
  File "/opt/python/weasyprint/css/__init__.py", line 27, in <module>
    from .computed_values import COMPUTER_FUNCTIONS
  File "/opt/python/weasyprint/css/computed_values.py", line 9, in <module>
    from ..text.ffi import ffi, pango, units_to_double
  File "/opt/python/weasyprint/text/ffi.py", line 431, in <module>
    pango = _dlopen(
  File "/opt/python/weasyprint/text/ffi.py", line 417, in _dlopen
    return ffi.dlopen(names[0])  # pragma: no cover
  File "/opt/python/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/opt/python/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/opt/python/cffi/api.py", line 827, in _load_backend_lib
    raise OSError(msg)INIT_REPORT Init Duration: 484.95 ms  Phase: invoke   Status: error   Error Type: Runtime.ExitError
START RequestId: 4f108313-e5e1-4849-bb42-caf4073c167e Version: $LATEST
Unknown application error occurred
Runtime.Unknown
END RequestId: 4f108313-e5e1-4849-bb42-caf4073c167e
REPORT RequestId: 4f108313-e5e1-4849-bb42-caf4073c167e  Duration: 485.85 ms Billed Duration: 486 ms Memory Size: 2048 MB    Max Memory Used: 54 MB  
XRAY TraceId: 1-661101b3-30d6e60c3e218f6e56880adf   SegmentId: 45c6dadf1be08203 Sampled: true
nrazon commented 6 months ago

Any idea on this error? I also created a new Linux2023 instance and cloned repo and executed "make build/weasyprint-layer-python3.12.zip" to create layer. but when I test it throws same error as [sks-keo] commented. I was using old python 3.8 version perfectly since today. But cannot be success on this latest version.

kalekseev commented 6 months ago

Can you try a layer from release? https://github.com/kotify/cloud-print-utils/releases/tag/weasyprint-61.1

nrazon commented 6 months ago

thanks very much @kalekseev I downloaded asset you provided and that worked. (I am not sure why the layer I build throws pandadoc exception but still that asset works for me).