Forums

wkhtmltopdf reported an error: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-' Exit with code 1 due to network error: UnknownNetworkError

hey,

I tried to export an pdf from my application using pdfkit package. the application works perfectly in my local computer. but in the server it shows me this error whne I click download :

wkhtmltopdf reported an error: QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-ELALLAKI' Exit with code 1 due to network error: UnknownNetworkError

Could you show how your pdfkit configuration looks like?

Here is how it looks like :

import os
import subprocess
import sys
try:
    FileNotFoundError
except NameError:
    FileNotFoundError = IOError


class Configuration(object):
    def __init__(self, wkhtmltopdf='', meta_tag_prefix='pdfkit-', environ=''):
        self.meta_tag_prefix = meta_tag_prefix

    self.wkhtmltopdf = wkhtmltopdf

    try:
        if not self.wkhtmltopdf:
            if sys.platform == 'win32':
                #hide cmd window
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = subprocess.SW_HIDE

                self.wkhtmltopdf = subprocess.Popen(
                    ['where.exe', 'wkhtmltopdf'], stdout=subprocess.PIPE, startupinfo=startupinfo).communicate()[0]
            else:
                self.wkhtmltopdf = subprocess.Popen(
                    ['which', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0]

        lines = self.wkhtmltopdf.splitlines()
        if len(lines) > 0:
            self.wkhtmltopdf = lines[0].strip()

        with open(self.wkhtmltopdf) as f:
            pass
    except (IOError, FileNotFoundError) as e:
        raise IOError('No wkhtmltopdf executable found: "%s"\n'
                      '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' % self.wkhtmltopdf)


    self.environ = environ

    if not self.environ:
        self.environ = os.environ

    for key in self.environ.keys():
        if not isinstance(self.environ[key], str):
            self.environ[key] = str(self.environ[key])

Could you also show full traceback?

yes sure :

OSError at /en/invoice-pdf/12
wkhtmltopdf reported an error:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-ELALLAKI'
Exit with code 1 due to network error: UnknownNetworkError
Request Method: GET
Request URL:    http://elallaki.pythonanywhere.com/en/invoice-pdf/12
Django Version: 3.2.19
Exception Type: OSError
Exception Value:    
wkhtmltopdf reported an error:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-ELALLAKI'
Exit with code 1 due to network error: UnknownNetworkError
Exception Location: /home/ELALLAKI/.virtualenvs/FacApp-virtualenv/lib/python3.7/site-packages/pdfkit/pdfkit.py, line 155, in handle_error
Python Executable:  /usr/local/bin/uwsgi
Python Version: 3.7.13
Python Path:    
['/home/ELALLAKI/FacApp',

Could you also provide the traceback from the error log, corresponding to this error message? (It looks like you copied the beginning of Django debugger error message)