# Buggy code
def on_finished(self, reply, capture_errors):
    status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    if not reply.isOpen() or not status_code:
        self.received_json.emit(None, reply.error())
        return

    performed_requests[self.request_id][4] = status_code

    data = reply.readAll()
    try:
        json_result = json.loads(str(data), encoding="latin_1")

        if "error" in json_result and capture_errors:
            self.show_error(TriblerRequestManager.get_message_from_error(json_result))
        else:
            self.received_json.emit(json_result, reply.error())
    except ValueError:
        self.received_json.emit(None, reply.error())
        logging.error("No json object could be decoded from data: %s" % data)

    # We disconnect the slot since we want the finished only to be emitted once. This allows us to reuse the
    # request manager.
    try:
        self.finished.disconnect()
        self.received_json.disconnect()
    except TypeError:
        pass  # We probably didn't have any connected slots.


# Traceback (AssertionError)
Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')
Stacktrace

Traceback (most recent call last):
File "c:\python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\test_as_server.py", line 58, in check
result = fun(*argv, **kwargs)
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\Core\Upgrade\test_config_upgrade_70_71.py", line 33, in test_read_test_libtribler_conf
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
File "c:\python27\lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "c:\python27\lib\unittest\case.py", line 753, in assertTupleEqual
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
File "c:\python27\lib\unittest\case.py", line 724, in assertSequenceEqual
self.fail(msg)
File "c:\python27\lib\unittest\case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')

# Fixed code
def on_finished(self, reply, capture_errors):
    status_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
    if not reply.isOpen() or not status_code:
        self.received_json.emit(None, reply.error())
        return

    if self.request_id in performed_requests:
        performed_requests[self.request_id][4] = status_code

    data = reply.readAll()
    try:
        json_result = json.loads(str(data), encoding="latin_1")

        if "error" in json_result and capture_errors:
            self.show_error(TriblerRequestManager.get_message_from_error(json_result))
        else:
            self.received_json.emit(json_result, reply.error())
    except ValueError:
        self.received_json.emit(None, reply.error())
        logging.error("No json object could be decoded from data: %s" % data)

    # We disconnect the slot since we want the finished only to be emitted once. This allows us to reuse the
    # request manager.
    try:
        self.finished.disconnect()
        self.received_json.disconnect()
    except TypeError:
        pass  # We probably didn't have any connected slots.