Skip to content

network error: ProtocolUnknownError while converting a local html file #232

@ankur0101

Description

@ankur0101

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions