ERPNext Webhooks are not working

We have configured ERPNext webhooks to communicate with our external applications. However, the webhooks have suddenly stopped working, and we are encountering the following error: [SSL: CERTIFICATE_VERIFY_FAILED]. It’s important to note that our external applications have valid and up-to-date SSL certificates.

Error:


requests.exceptions.SSLError: HTTPSConnectionPool(host='{mysite name}', port=443): Max retries exceeded with url: /api/sales_invoice/webhook/v1/create (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/rq/worker.py", line 1418, in perform_job
    rv = job.perform()
         ^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/rq/job.py", line 1225, in perform
    self._result = self._execute()
                   ^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/env/lib/python3.11/site-packages/rq/job.py", line 1262, in _execute
    result = self.func(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 194, in execute_job
    retval = method(**kwargs)
             ^^^^^^^^^^^^^^^^
  File "/home/frappe/frappe-bench/apps/frappe/frappe/integrations/doctype/webhook/webhook.py", line 152, in enqueue_webhook
    log_request(webhook.name, doc.name, webhook.request_url, headers, data, r)
                                                                            ^
UnboundLocalError: cannot access local variable 'r' where it is not associated with a value