# Buggy code
def _create_connect_string(param):
    """
    create the connectstring

    Port, Password, conParams, Driver, User,
    Server, Database
    """
    port = ""
    password = ""
    conParams = ""
    if param.get("Port"):
        port = ":{0!s}".format(param.get("Port"))
    if param.get("Password"):
        password = ":{0!s}".format(param.get("Password"))
    if param.get("conParams"):
        conParams = "?{0!s}".format(param.get("conParams"))
    connect_string = "{0!s}://{1!s}{2!s}{3!s}{4!s}{5!s}/{6!s}{7!s}".format(
        param.get("Driver", ""),
        param.get("User", ""),
        password,
        "@" if (param.get("User") or password) else "",
        param.get("Server", ""),
        port,
        param.get("Database", ""),
        conParams,
    )
    # SQLAlchemy does not like a unicode connect string!
    if param.get("Driver").lower() == "sqlite":
        connect_string = str(connect_string)
    return connect_string


# Traceback (UnicodeDecodeError)
[2018-08-14 14:49:53,123] ERROR in app: Exception on /system/documentation [GET]
Traceback (most recent call last):
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/fred/privacyidea/privacyidea/privacyidea/api/lib/prepolicy.py", line 120, in policy_wrapper
return wrapped_function(*args, **kwds)
File "/home/fred/privacyidea/privacyidea/privacyidea/api/auth.py", line 316, in decorated_function
return f(*args, **kwargs)
File "/home/fred/privacyidea/privacyidea/privacyidea/api/system.py", line 113, in get_config_documentation
context=context))
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/templating.py", line 135, in render_template
context, ctx.app)
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/flask/templating.py", line 117, in _render
rv = template.render(context)
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/home/fred/privacyidea/privacyidea/venv/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/fred/privacyidea/privacyidea/privacyidea/static/templates/documentation.rst", line 56, in top-level template code
{{k}}: **{{v}}**
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 8: ordinal not in range(128)

# Fixed code
def _create_connect_string(param):
    """
    create the connectstring

    Port, Password, conParams, Driver, User,
    Server, Database
    """
    port = ""
    password = ""
    conParams = ""
    if param.get("Port"):
        port = ":{0!s}".format(param.get("Port"))
    if param.get("Password"):
        password = ":{0!s}".format(param.get("Password"))
    if param.get("conParams"):
        conParams = "?{0!s}".format(param.get("conParams"))
    connect_string = "{0!s}://{1!s}{2!s}{3!s}{4!s}{5!s}/{6!s}{7!s}".format(
        param.get("Driver", ""),
        param.get("User", ""),
        password,
        "@" if (param.get("User") or password) else "",
        param.get("Server", ""),
        port,
        param.get("Database", ""),
        conParams,
    )
    # SQLAlchemy does not like a unicode connect string!
    if param.get("Driver").lower() == "sqlite":
        connect_string = str(connect_string)
    return connect_string