Forums

XDG_RUNTIME_DIR not set

HI I have a problem with exporting pdf with pdfkit library and wkhtmltopdf i got the msg error:

2022-03-18 13:27:11,669: Exception on /logbook/ALL/3/2022/ALL/ALL/true [GET] Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2051, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1501, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1499, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1485, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(req.view_args) File "/usr/local/lib/python3.9/site-packages/flask_login/utils.py", line 272, in decorated_view return func(*args, kwargs) File "/home/maystropilot/flightlog/flightlogbook/routes.py", line 93, in logbook_data pdff = pdfkit.from_string(rendered,False) File "/home/maystropilot/.local/lib/python3.9/site-packages/pdfkit/api.py", line 75, in from_string return r.to_pdf(output_path) File "/home/maystropilot/.local/lib/python3.9/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf self.handle_error(exit_code, stderr) File "/home/maystropilot/.local/lib/python3.9/site-packages/pdfkit/pdfkit.py", line 155, in handle_error raise IOError('wkhtmltopdf reported an error:\n' + stderr) OSError: wkhtmltopdf reported an error: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-maystropilot' Exit with code 1 due to network error: UnknownNetworkError

It looks like this SO answer has your solution, except that you do not need to install xvfb because it's already installed.

I have the same issue. My app runs perfectly and it prints all my pdf pages perfectly with headers locally.

But when I run my app on pythonanywhere, headers on pages (except first page) are not printed.

I have the same issue. My app runs perfectly and it prints all my pdf pages perfectly with headers locally.

But when I run my app on pythonanywhere, headers on pages (except first page) are not printed.

Are the elements that make up the headers (images etc) available to your code on PythonAnywhere?