python-pdfkit icon indicating copy to clipboard operation
python-pdfkit copied to clipboard

network error: ProtocolUnknownError while converting a local html file

Open ankur0101 opened this issue 3 years ago • 1 comments

Hi, I am trying to convert a local html file (via flask) which has external css and it results in below error:

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

Since it is a client code, I cant paste the content of html file, the code from python file is as below:

from flask import Flask, make_response, render_template, request, jsonify
import pdfkit

app = Flask(__name__, template_folder='/home/ubuntu/html2pdf')
@app.route('/', methods=['GET'])
def return_pdf():
        pdf = pdfkit.from_file('/home/ubuntu/html2pdf/sample.html')
        response = make_response(pdf)
        response.headers['Content-Type'] = 'application/pdf'
        response.headers['Content-Disposition'] = 'inline; filename=myresponse.pdf'
        return response

if __name__ == '__main__':
        app.run(debug=True, host='0.0.0.0', port=5002)

I am clueless what is wrong and how to debug it, need help

ankur0101 avatar Jul 18 '22 12:07 ankur0101

i have this issue too and enable-local-file-access didn't help

BenjaminHoegh avatar Sep 09 '22 11:09 BenjaminHoegh