<commit_before>from __future__ import absolute_import, division, print_function

import linecache
import logging
import os
import sys
import threading
import traceback

import bugsnag
from six.moves.urllib.request import (
    Request,
    urlopen,
    ProxyHandler,
    build_opener,
    install_opener
)
from bugsnag.utils import fully_qualified_class_name as class_name
from bugsnag.utils import SanitizingJSONEncoder, package_version


def deliver(payload, url, async, proxy_host):
    req = Request(url, payload.encode('utf-8', 'replace'), {
        'Content-Type': 'application/json'
    })

    def request():
        if proxy_host:
            proxy = ProxyHandler({
                'https': proxy_host,
                'http': proxy_host
            })
            opener = build_opener(proxy)
            install_opener(opener)
        try:
            resp = urlopen(req)
            status = resp.getcode()

            if status != 200:
                bugsnag.log("Notification to %s failed, status %d" % (url,
                                                                      status))

        except Exception:
            try:
                bugsnag.log("Notification to %s failed" % (req.get_full_url()))
                print((traceback.format_exc()))
            except Exception:
                print(("[BUGSNAG] error in request thread exception handler."))
                pass

    t = threading.Thread(target=request)<commit_msg>Log error message when notification fails<commit_after>from __future__ import absolute_import, division, print_function

import linecache
import logging
import os
import sys
import threading
import traceback

import bugsnag
from six.moves.urllib.request import (
    Request,
    urlopen,
    ProxyHandler,
    build_opener,
    install_opener
)
from bugsnag.utils import fully_qualified_class_name as class_name
from bugsnag.utils import SanitizingJSONEncoder, package_version


def deliver(payload, url, async, proxy_host):
    req = Request(url, payload.encode('utf-8', 'replace'), {
        'Content-Type': 'application/json'
    })

    def request():
        if proxy_host:
            proxy = ProxyHandler({
                'https': proxy_host,
                'http': proxy_host
            })
            opener = build_opener(proxy)
            install_opener(opener)
        try:
            resp = urlopen(req)
            status = resp.getcode()

            if status != 200:
                bugsnag.log("Notification to %s failed, status %d" % (url,
                                                                      status))

        except Exception as e:
            try:
                msg = "Notification to %s failed: %s" % (req.get_full_url(), e)
                bugsnag.log(msg)
                print((traceback.format_exc()))
            except Exception:
                print(("[BUGSNAG] error in request thread exception handler."))
                pass

    t = threading.Thread(target=request)
{'fraction_non_alphanumeric': 0.08573342263898191, 'fraction_numerical': 0.0026791694574681848, 'mean_word_length': 1.931305201177625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6778713', 'n_tokens_mistral': 809, 'n_tokens_neox': 776, 'n_words': 210}