def deliver(payload, url, async): payload = json_encode(payload) req = Request(url, payload, {'Content-Type': 'application/json'}) def request(): 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) t.start() if not async: t.join()
def deliver(payload, url, async): payload = json_encode(payload) req = Request(url, payload, { 'Content-Type': 'application/json' }) def request(): 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) t.start() if not async: t.join()
def test_json_encode(self): payload = {"a": u("a") * 512 * 1024} encoded = ('{"a": "' + 'a' * 1024 + '"}').encode('utf-8', 'replace') self.assertEqual(json_encode(payload), encoded)
def test_json_encode(): payload = {"a": u("a") * 512 * 1024} eq_(json_encode(payload), ('{"a": "' + 'a' * 1024 + '"}').encode('utf-8', 'replace'))