R
Join ServerRailway
βο½help
FastAPI - wkhtmltopdf
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!!
a460e728-9647-40f6-811c-fe5d99abb663
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
I have also tried to do it in the railway.json
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
/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
could you undo everything you have tried and then give me the error again? you may have made things worse
haha oops! Let's do it again
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)
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)
please remove any attempts you are making at installing wkhtmltopdf yourself, and then show me the error
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''"
remove any aptfiles and NIXPACKS_APT_PKGS
Yep, all done
in this you mention NIXPACKS_APT_PKGS with value wkhtmltopdf, if you remove this variable do you still get the same error
im looking for the error before you started trying to fix this yourself
Sorry, let me clarify...it builds properly yes but when I actually test my app it just says wkhtmltopdf doesn't exist
If you look at the most recent error in the deploy logs you can see it
maybe there is some confusion here, i cant access your project at all
thats why im asking for you to provide me with the error before you started trying to fix it yourself
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
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
So this is the error when the package doesn't exist at all
This is what the app was at before I tried fixing it myself
there we go, finally thats what i was asking for
Sorry about that!
add this as a
nixpacks.toml
file to your project[phases.setup]
nixPkgs = ["...", "wkhtmltopdf-bin"]
untested of course, so i am not fully sure this would work
Let's give it a shot!
There we go! Works beautifully!
You are the best, thanks!
no problem, glad i could help π