# Buggy code
def getUserInfo(self, userId):
    """
    This function returns all user info for a given userid/object.

    :param userId: The userid of the object
    :type userId: string
    :return: A dictionary with the keys defined in self.userinfo
    :rtype: dict
    """
    ret = {}
    self._bind()

    if self.uidtype.lower() == "dn":
        # encode utf8, so that also german ulauts work in the DN
        self.l.search(
            search_base=to_utf8(userId),
            search_scope=self.scope,
            search_filter="(&" + self.searchfilter + ")",
            attributes=self.userinfo.values(),
        )
    else:
        filter = "(&%s(%s=%s))" % (self.searchfilter, self.uidtype, userId)
        self.l.search(
            search_base=self.basedn,
            search_scope=self.scope,
            search_filter=filter,
            attributes=self.userinfo.values(),
        )

    r = self.l.response
    r = self._trim_result(r)
    if len(r) > 1:  # pragma: no cover
        raise Exception("Found more than one object for uid %r" % userId)

    for entry in r:
        attributes = entry.get("attributes")
        ret = self._ldap_attributes_to_user_object(attributes)

    return ret


# Traceback (UnicodeDecodeError)
Found this userlist: [...list of users...]
Found this userlist: [...list of users...]
Exiting get_user_list with result [...list of users...]
Exiting get_user_list with result [...list of users...]
Exception on /user/ [GET]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/lib/prepolicy.py", line 96, in policy_wrapper
    return wrapped_function(*args, **kwds)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/auth.py", line 302, in decorated_function
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/user.py", line 104, in get_users
    return send_result(users)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/lib/utils.py", line 122, in send_result
    return jsonify(res)
  File "/usr/lib/python2.7/dist-packages/flask/json.py", line 238, in jsonify
    indent=indent),
  File "/usr/lib/python2.7/dist-packages/flask/json.py", line 126, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 369, in dumps
    **kw).encode(obj)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 264, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 612, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 568, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 568, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 455, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 535, in _iterencode_dict
    yield _encoder(value)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
Exception on /user/ [GET]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/lib/prepolicy.py", line 96, in policy_wrapper
    return wrapped_function(*args, **kwds)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/auth.py", line 302, in decorated_function
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/user.py", line 104, in get_users
    return send_result(users)
  File "/usr/lib/python2.7/dist-packages/privacyidea/api/lib/utils.py", line 122, in send_result
    return jsonify(res)
  File "/usr/lib/python2.7/dist-packages/flask/json.py", line 238, in jsonify
    indent=indent),
  File "/usr/lib/python2.7/dist-packages/flask/json.py", line 126, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 369, in dumps
    **kw).encode(obj)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 264, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 612, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 568, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 568, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 455, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/dist-packages/simplejson/encoder.py", line 535, in _iterencode_dict
    yield _encoder(value)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xd6 in position 0: invalid continuation byte
Can not get param: No JSON object could be decoded
Can not get param: No JSON object could be decoded

# Fixed code
def getUserInfo(self, userId):
    """
    This function returns all user info for a given userid/object.

    :param userId: The userid of the object
    :type userId: string
    :return: A dictionary with the keys defined in self.userinfo
    :rtype: dict
    """
    ret = {}
    self._bind()

    if self.uidtype.lower() == "dn":
        # encode utf8, so that also german ulauts work in the DN
        self.l.search(
            search_base=to_utf8(userId),
            search_scope=self.scope,
            search_filter="(&" + self.searchfilter + ")",
            attributes=self.userinfo.values(),
        )
    else:
        if self.uidtype == "objectGUID":
            userId = uuid.UUID("{%s}" % userId).bytes_le
            userId = escape_bytes(userId)
        filter = "(&%s(%s=%s))" % (self.searchfilter, self.uidtype, userId)
        self.l.search(
            search_base=self.basedn,
            search_scope=self.scope,
            search_filter=filter,
            attributes=self.userinfo.values(),
        )

    r = self.l.response
    r = self._trim_result(r)
    if len(r) > 1:  # pragma: no cover
        raise Exception("Found more than one object for uid %r" % userId)

    for entry in r:
        attributes = entry.get("attributes")
        ret = self._ldap_attributes_to_user_object(attributes)

    return ret