# Buggy code
def ask_passkey(
    self, dialog_msg, notify_msg, is_numeric, notification, device_path, ok, err
):
    def passkey_dialog_cb(dialog, response_id):
        if response_id == Gtk.ResponseType.ACCEPT:
            ret = pin_entry.get_text()
            if is_numeric:
                ret = GLib.Variant("(u)", int(ret))
            ok(ret)
        else:
            err(BluezErrorRejected("Rejected"))
        dialog.destroy()
        self.dialog = None

    dev_str = self.get_device_string(device_path)
    notify_message = _("Pairing request for %s") % dev_str

    if self.dialog:
        logging.info("Agent: Another dialog still active, cancelling")
        err(BluezErrorCanceled("Canceled"))

    self.dialog, pin_entry = self.build_passkey_dialog(dev_str, dialog_msg, is_numeric)
    if not self.dialog:
        logging.error("Agent: Failed to build dialog")
        err(BluezErrorCanceled("Canceled"))

    if notification:
        Notification(
            _("Bluetooth Authentication"), notify_message, icon_name="blueman"
        ).show()

    self.dialog.connect("response", passkey_dialog_cb)
    self.dialog.present()


# Traceback (TypeError)
(blueman-tray:79548): Gdk-CRITICAL **: 16:36:17.940: gdk_window_thaw_toplevel_updates: assertion 'window->update_and_descendants_freeze_count > 0' failed
blueman-manager version 2.1.1 starting
Stale PID, overwriting
blueman-manager 16.36.23 WARNING  DeviceList:193 monitor_power_levels: Failed to get power levels, probably a LE device.
blueman-manager 16.36.33 WARNING  DeviceList:193 monitor_power_levels: Failed to get power levels, probably a LE device.
/usr/lib/python3.8/site-packages/gi/overrides/Gtk.py:1630: Warning: g_value_get_int: assertion 'G_VALUE_HOLDS_INT (value)' failed
return _Gtk_main(*args, **kwargs)
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/gi/overrides/GLib.py", line 130, in _create
iter(value)
TypeError: 'int' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/blueman/main/applet/BluezAgent.py", line 172, in passkey_dialog_cb
ret = GLib.Variant('(u)', int(ret))
File "/usr/lib/python3.8/site-packages/gi/overrides/GLib.py", line 189, in __new__
v = creator._create(format_string, value)
File "/usr/lib/python3.8/site-packages/gi/overrides/GLib.py", line 132, in _create
raise TypeError("Could not create array, tuple or dictionary entry from non iterable value %s %s" %
TypeError: Could not create array, tuple or dictionary entry from non iterable value (u) 401704
blueman-manager 16.37.04 ERROR    Manager:201 error_handler:  Authentication Canceled
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/blueman/bluez/Base.py", line 81, in callback
value = proxy.call_finish(result).unpack()
gi.repository.GLib.GError: g-io-error-quark: GDBus.Error:org.bluez.Error.AuthenticationCanceled: Authentication Canceled (36)

# Fixed code
def ask_passkey(
    self, dialog_msg, notify_msg, is_numeric, notification, device_path, ok, err
):
    def passkey_dialog_cb(dialog, response_id):
        if response_id == Gtk.ResponseType.ACCEPT:
            ret = pin_entry.get_text()
            ok(int(ret) if is_numeric else ret)
        else:
            err(BluezErrorRejected("Rejected"))
        dialog.destroy()
        self.dialog = None

    dev_str = self.get_device_string(device_path)
    notify_message = _("Pairing request for %s") % dev_str

    if self.dialog:
        logging.info("Agent: Another dialog still active, cancelling")
        err(BluezErrorCanceled("Canceled"))

    self.dialog, pin_entry = self.build_passkey_dialog(dev_str, dialog_msg, is_numeric)
    if not self.dialog:
        logging.error("Agent: Failed to build dialog")
        err(BluezErrorCanceled("Canceled"))

    if notification:
        Notification(
            _("Bluetooth Authentication"), notify_message, icon_name="blueman"
        ).show()

    self.dialog.connect("response", passkey_dialog_cb)
    self.dialog.present()