【问题标题】:Exit with code 1 due to network error: ProtocolUnknownError由于网络错误而退出代码 1:ProtocolUnknownError
【发布时间】:2021-11-11 11:25:26
【问题描述】:
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 - - [11/Nov/2021 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

【问题讨论】:

    标签: flask pdf-generation aws-api-gateway python-3.7


    【解决方案1】:

    您应该尝试添加此选项:

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

    到你的选项字典

    斯蒂芬

    【讨论】:

    • 是的,明白了!谢谢
    猜你喜欢
    • 2017-06-01
    • 2020-12-06
    • 1970-01-01
    • 2014-11-15
    • 2017-11-14
    • 2018-01-11
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    相关资源
    最近更新 更多