首页 > 解决方案 > 由于网络错误而退出代码 1:ProtocolUnknownError

问题描述

from flask import Flask, render_template, make_response
import pdfkit
        
app = Flask(__name__)
              

    @app.route('/<Customer_Full_Name>/<Customer_adress>/<customerID_number>/<CurrentDate>/<Digital_Signature>')
            def pdf_template(Customer_Full_Name, Customer_adress, customerID_number,CurrentDate,Digital_Signature):
                rendered = render_template('pdf_template.html', Customer_Full_Name=Customer_Full_Name,Customer_adress=Customer_adress,customerID_number=customerID_number, CurrentDate=CurrentDate, Digital_Signature=Digital_Signature)
    pdf = pdfkit.from_string(rendered)
    response = make_response(pdf, False)
    response.headers['Content-Type'] = 'application/pdf'
    response.headers['Content-Disposition'] = 'inline;filename=output'

    return response
                # return render_template('pdf_template.html')
            
                
      if __name__ == '__main__':
       app.run(debug=True)

127.0.0.1 - - [2021 年 11 月 11 日 16:56:58] “GET /Customer_Fl_Name/Customedress/customD_number/CurntDate/Dil_Signature HTTP/1.1”500 -

flask run输出:

 * Serving Flask app 'app.py' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2021-11-11 16:58:20,679] ERROR in app: Exception on /Customer_Fl_Name/Customedress/customD_number/CurntDate/Dil_Signature [GET]
Traceback (most recent call last):
  File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/swapnil/Desktop/Clinsj_Certificate/app.py", line 11, in pdf_template
    pdf = pdfkit.from_string(rendered, False)
  File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/pdfkit/api.py", line 72, in from_string
    return r.to_pdf(output_path)
  File "/Users/swapnil/Desktop/Clinsj_Certificate/venv/lib/python3.7/site-packages/pdfkit/pdfkit.py", line 156, in to_pdf
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Loading pages (1/6)
Warning: Blocked access to file                                   
Warning: Blocked access to file 
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Counting pages (2/6)                                               
Resolving links (4/6)                                                       
Loading headers and footers (5/6)                                           
Printing pages (6/6)
Done                                                                      
Exit with code 1 due to network error: ProtocolUnknownError

标签: flaskpdf-generationaws-api-gatewaypython-3.7

解决方案


您应该尝试添加此选项:

"enable-local-file-access": ""

到你的选项字典

斯蒂芬妮


推荐阅读