R

Railway

βœ‹ο½œhelp

Join Server

FastAPI - wkhtmltopdf

Bbennettcolecohen5/18/2023
Hi there - I have a FastAPI server that requires wkhtmltopdf to run. I added an Aptfile to my repo but it doesn't seem to be getting picked up Railway. Any tips? Thanks!!
Bbennettcolecohen5/18/2023
a460e728-9647-40f6-811c-fe5d99abb663
Bbennettcolecohen5/18/2023
I've added it as an environment variable: NIXPACKS_APT_PKGS yet it still errors when running (it is there but does not run properly).

I have also tried to do it in the railway.json
Bbennettcolecohen5/18/2023
Here is the actual error that shows up when endpoint is pinged:

/bin/wkhtmltopdf: /nix/store/wprxx5zkkk13hpj6k1v6qadjylh3vq9m-gcc-11.3.0-lib/lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libQt5WebKit.so.5)
INFO: 192.168.0.2:43880 - "GET / HTTP/1.1" 200 OK
Bbrody5/18/2023
could you undo everything you have tried and then give me the error again? you may have made things worse
Bbennettcolecohen5/18/2023
haha oops! Let's do it again
Bbennettcolecohen5/18/2023
Okay, so when I don't do anything with the Aptfile, etc it of course shows no wkhtmltopdf exists (OSError: No wkhtmltopdf executable found: "b''")

When I add an environment variable for NIXPACKS_APT_PKGS with value wkhtmltopdf, I see that it is being installed in the build logs which is a good sign. This is the error I get starting from where it's relevant

pdf_bytes = pdfkit.from_string(html, False)
File "/opt/venv/lib/python3.8/site-packages/pdfkit/api.py", line 75, in from_string
return r.to_pdf(output_path)
File "/opt/venv/lib/python3.8/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
self.handle_error(exit_code, stderr)
File "/opt/venv/lib/python3.8/site-packages/pdfkit/pdfkit.py", line 158, in handle_error
raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, error_msg))
OSError: wkhtmltopdf exited with non-zero code 1. error:
/bin/wkhtmltopdf: /nix/store/wprxx5zkkk13hpj6k1v6qadjylh3vq9m-gcc-11.3.0-lib/lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /lib/x86_64-linux-gnu/libQt5WebKit.so.5)
Bbrody5/18/2023
please remove any attempts you are making at installing wkhtmltopdf yourself, and then show me the error
Bbennettcolecohen5/18/2023
Sorry, I'm not quite sure what you mean? When I don't have it anywhere in my code, the error is as shown above: OSError: No wkhtmltopdf executable found: "b''"
Bbrody5/18/2023
remove any aptfiles and NIXPACKS_APT_PKGS
Bbennettcolecohen5/18/2023
Yep, all done
Bbrody5/18/2023
in this you mention NIXPACKS_APT_PKGS with value wkhtmltopdf, if you remove this variable do you still get the same error
Bbrody5/18/2023
im looking for the error before you started trying to fix this yourself
Bbennettcolecohen5/18/2023
Sorry, let me clarify...it builds properly yes but when I actually test my app it just says wkhtmltopdf doesn't exist
Bbennettcolecohen5/18/2023
If you look at the most recent error in the deploy logs you can see it
Bbrody5/18/2023
maybe there is some confusion here, i cant access your project at all
Bbrody5/18/2023
thats why im asking for you to provide me with the error before you started trying to fix it yourself
Bbennettcolecohen5/18/2023
pdf_bytes = pdfkit.from_string(html, False)
File "/opt/venv/lib/python3.8/site-packages/pdfkit/api.py", line 72, in from_string
r = PDFKit(input, 'string', options=options, toc=toc, cover=cover, css=css,
File "/opt/venv/lib/python3.8/site-packages/pdfkit/pdfkit.py", line 45, in init
self.configuration = (Configuration() if configuration is None
File "/opt/venv/lib/python3.8/site-packages/pdfkit/configuration.py", line 38, in init
raise IOError('No wkhtmltopdf executable found: "%s"\n'
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
Bbennettcolecohen5/18/2023
So this is the error when the package doesn't exist at all
Bbennettcolecohen5/18/2023
This is what the app was at before I tried fixing it myself
Bbrody5/18/2023
there we go, finally thats what i was asking for
Bbennettcolecohen5/18/2023
Sorry about that!
Bbrody5/18/2023
add this as a nixpacks.toml file to your project
[phases.setup]
nixPkgs = ["...", "wkhtmltopdf-bin"]
Bbrody5/18/2023
untested of course, so i am not fully sure this would work
Bbennettcolecohen5/18/2023
Let's give it a shot!
Bbennettcolecohen5/18/2023
There we go! Works beautifully!
Bbennettcolecohen5/18/2023
You are the best, thanks!
Bbrody5/18/2023
no problem, glad i could help πŸ™‚