balbarak / WeasyPrint-netcore

WeasyPrint Wrapper for .Net on Windows
BSD 3-Clause "New" or "Revised" License
71 stars 19 forks source link

Running in an Azure Function #19

Open Ayiadim opened 3 years ago

Ayiadim commented 3 years ago

Hello,

This isn't really an issue with the package itself but more of a question to see if anyone else has had this problem.

I've added this package to a .NET azure function, it works fine locally but as soon as it is deployed to the cloud I get these errors:

Encoding web name: ; code page: ''

Force kill process on cancellation: 'True'

Traceback (most recent call last):

return _run_code(code, main_globals, None,

exec(code, run_globals)

File "scripts\weasyprint.exe\__main__.py", line 4, in <module>

from .css import preprocess_stylesheet # noqa isort:skip

from . import computed_values, media_queries

from .. import text

import cairocffi as cairo

cairo = dlopen(

raise OSError(error_message) # pragma: no cover

OSError: no library called "cairo" was found

cannot load library 'gtk3\libcairo-2.dll': error 0x7f

cannot load library 'libcairo.so': error 0x7e

cannot load library 'libcairo.2.dylib': error 0x7e

cannot load library 'libcairo-2.dll': error 0x7f

Finished process 4688 with exit code 1, and elapsed time 00:00:01.7287848.

It looks like the dependencies are failing, I've added python 3.6.4 x64 and x86 as an extension but it didn't seem to solve the problem.

Any help would be appreciated, thanks.

berthertogen commented 2 years ago

Is your function running in Windows? This package needs to run under windows.

jektvik commented 2 years ago

Have the same problem on my Azure WebApp -> exact same crash response OSError: no library called "cairo" was found. It's a windows based instance indeed.

berthertogen commented 2 years ago

I've created an alternate package https://github.com/berthertogen/weasyprint.wrapped which supports Windows as well as Linux. Haven't tested it in a azure function though. You might give that a try?

jektvik commented 2 years ago

That alternate package also fails with a missing library, this time it's:

cannot load library 'pango-1.0-0'

We're still on a managed web app environment in Azure. It works locally on my machine so I don't know how these environments are different but there must be something different. I'm not a python developer to debug this efficiently enough i.e. mostly would be good to understand why he finds these missing libraries on my local machine but not on azure.

berthertogen commented 1 year ago

Hello @jektvik, I've done some more research on the subject after having an issue submitted on the other repo as well. More info here https://github.com/berthertogen/weasyprint.wrapped/issues/39#issuecomment-1367331090.

TLDR: The Azure App Services/Functions are missing components which aren't in python packages (and thus cannot be packaged). The provided solution provides an asp.net container with the necessary components, Azure App Services/Functions can run this container (or an extension of that container with your sources on it).

I have researched the Azure App Service Container options and got it working, if you like to use it in an Azure App Function as well could you give me a poke in this issue and I'll investigate and provide an example.

jektvik commented 1 year ago

Hi @berthertogen thanks for reverting. Containers are unfortunately a headache for us at this moment as we do not have the facility to build containers yet (not even locally, no comment, but it is what it is).