WebSocket connection Issue in wkhtmltopdf while downloading invoice pdf

While downloading the PDF using the print format, I’m encountering the following error: “wkhtmltopdf reported an error: Exit with code 1 due to network error: TimeoutError.”

Additionally, I’m unable to generate the invoice using a custom format with the print designer. Simultaneously, in the console, I’m seeing “WebSocket Connection Failures” with the URL wss://DOMAIN/?EIO=4&transport=websocket&sid=....

Could you provide any suggestions or insights to address these issues? Your help would be greatly appreciated!

@Mohammadsami_Bakhtya check this OSError: wkhtmltopdf reported an error: Exit with code 1 due to network error: SslHandshakeFailedError

Can you help for prod mode?
We are using docker and we had added below config,
“host_name”: “http://127.0.0.1:8000” and then tried with domain also but not working.

@Mohammadsami_Bakhtya check this Wkhtmltopdf error creating PDF

We also tried Wkhtmltopdf error creating PDF
and added below config, but now working.

 "restart_supervisor_on_update": true,
 "restart_systemd_on_update": true,
 "host_name": "https://mydomain.com"

Actually we are getting connection timeout error not refused or SslHandshake.

And in console, everytime getting WebSocket connection Issue.

I have added the error log below and we also have one question, if you check the
log, it is using http instead of https.

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/app.py", line 114, in application
    response = frappe.api.handle(request)
      request = <Request 'http://reliable.fusionsofttech.co.in/api/method/frappe.utils.print_format.download_pdf?doctype=Sales+Invoice&name=REL&format=CustomSalesInvoicePrint&_lang=en' [GET]>
      response = None
      rollback = True
      e = OSError('wkhtmltopdf reported an error:\nExit with code 1 due to network error: TimeoutError\n')
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
      request = <Request 'http://reliable.fusionsofttech.co.in/api/method/frappe.utils.print_format.download_pdf?doctype=Sales+Invoice&name=REL&format=CustomSalesInvoicePrint&_lang=en' [GET]>
      endpoint = <function handle_rpc_call at 0x7f46e8be2f20>
      arguments = {'method': 'frappe.utils.print_format.download_pdf'}
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
      method = 'frappe.utils.print_format.download_pdf'
      frappe = <module 'frappe' from 'apps/frappe/frappe/__init__.py'>
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
      cmd = 'frappe.utils.print_format.download_pdf'
      data = None
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
      cmd = 'frappe.utils.print_format.download_pdf'
      from_async = False
      server_script = None
      method = <function download_pdf at 0x7f46e450eb60>
  File "apps/frappe/frappe/__init__.py", line 1768, in call
    return fn(*args, **newargs)
      fn = <function download_pdf at 0x7f46e450eb60>
      args = ()
      kwargs = {'doctype': 'Sales Invoice', 'name': 'REL', 'format': 'CustomSalesInvoicePrint', '_lang': 'en', 'cmd': 'frappe.utils.print_format.download_pdf'}
      newargs = {'doctype': 'Sales Invoice', 'name': 'REL', 'format': 'CustomSalesInvoicePrint'}
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
      args = ()
      kwargs = {'doctype': 'Sales Invoice', 'name': 'REL', 'format': 'CustomSalesInvoicePrint'}
      apply_condition = <function whitelist.<locals>.innerfn.<locals>.<lambda> at 0x7f46e450eac0>
      func = <function download_pdf at 0x7f46e450ea20>
  File "apps/frappe/frappe/utils/print_format.py", line 234, in download_pdf
    pdf_file = frappe.get_print(
      doctype = 'Sales Invoice'
      name = 'REL'
      format = 'CustomSalesInvoicePrint'
      doc = <SalesInvoice: REL docstatus=1>
      no_letterhead = 0
      language = None
      letterhead = None
  File "apps/frappe/frappe/__init__.py", line 2184, in get_print
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html
      doctype = 'Sales Invoice'
      name = 'REL'
      print_format = 'CustomSalesInvoicePrint'
      style = None
      as_pdf = True
      doc = <SalesInvoice: REL docstatus=1>
      output = None
      no_letterhead = 0
      password = ********
      pdf_options = {}
      letterhead = None
      get_pdf = <function get_pdf at 0x7f46e450d9e0>
      get_response_without_exception_handling = <function get_response_without_exception_handling at 0x7f46e7399d00>
      original_form_dict = {'doctype': 'Sales Invoice', 'name': 'REL', 'format': 'CustomSalesInvoicePrint', '_lang': 'en', 'cmd': 'frappe.utils.print_format.download_pdf'}
      response = <Response 70944 bytes [200 OK]>
      
	....
	....
	
	
      toc = None
      cover = None
      css = None
      configuration = None
      cover_first = False
      verbose = True
      r = <pdfkit.pdfkit.PDFKit object at 0x7f46dff6c390>
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
    
    	....
	....
    
      stderr = 'Exit with code 1 due to network error: TimeoutError\n'
      exit_code = 1
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
      exit_code = 1
      stderr = 'Exit with code 1 due to network error: TimeoutError\n'
      stderr_lines = ['Exit with code 1 due to network error: TimeoutError']
builtins.OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: TimeoutError