# Buggy code
def get_app_kwds(cls, config_section, app_name=None):
    kwds = {
        "config_file": None,
        "config_section": config_section,
    }
    uwsgi_opt = uwsgi.opt
    config_file = None
    # check for --set galaxy_config_file=<path>, this overrides whatever config file uWSGI was loaded with (which
    # may not actually include a Galaxy config)
    if uwsgi_opt.get("galaxy_config_file"):
        config_file = uwsgi_opt.get("galaxy_config_file")
    # check for --yaml or --json uWSGI config options next
    if config_file is None:
        config_file = UWSGIApplicationStack._get_config_file(
            uwsgi_opt.get("yaml"), yaml.safe_load, config_section
        ) or UWSGIApplicationStack._get_config_file(
            uwsgi_opt.get("json"), json.load, config_section
        )
    # --ini and --ini-paste don't behave the same way, but this method will only be called by mules if the main
    # application was loaded with --ini-paste, so we can make some assumptions, most notably, uWSGI does not have
    # any way to set the app name when loading with paste.deploy:loadapp(), so hardcoding the alternate section
    # name to `app:main` is fine.
    has_ini_config = (
        config_file is None and uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste")
    )
    has_ini_config = has_ini_config or (
        config_file and has_ext(config_file, "ini", aliases=True, ignore="sample")
    )
    if has_ini_config:
        config_file = config_file or uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste")
        parser = nice_config_parser(config_file)
        if not parser.has_section(config_section) and parser.has_section("app:main"):
            kwds["config_section"] = "app:main"
    kwds["config_file"] = config_file
    return kwds


# Traceback (TypeError)
Traceback (most recent call last):
File "lib/galaxy/webapps/galaxy/buildapp.py", line 184, in uwsgi_app
return galaxy.web.framework.webapp.build_native_uwsgi_app(app_factory, "galaxy")
File "lib/galaxy/web/framework/webapp.py", line 965, in build_native_uwsgi_app
uwsgi_app = paste_factory({}, load_app_kwds=app_kwds)
File "lib/galaxy/webapps/galaxy/buildapp.py", line 41, in app_factory
**load_app_kwds
File "lib/galaxy/util/properties.py", line 84, in load_app_properties
properties.update(dict(parser.items(config_section)))
File "/usr/lib/python3.5/configparser.py", line 855, in items
return [(option, value_getter(option)) for option in d.keys()]
File "/usr/lib/python3.5/configparser.py", line 855, in <listcomp>
return [(option, value_getter(option)) for option in d.keys()]
File "/usr/lib/python3.5/configparser.py", line 852, in <lambda>
section, option, d[option], d)
File "lib/galaxy/util/properties.py", line 162, in before_get
value, defaults)
File "/usr/lib/python3.5/configparser.py", line 393, in before_get
self._interpolate_some(parser, option, L, value, section, defaults, 1)
File "/usr/lib/python3.5/configparser.py", line 410, in _interpolate_some
p = rest.find("%")
TypeError: Error in file b'/path/to/galaxy/config/galaxy.ini': a bytes-like object is required, not 'str'

# Fixed code
def get_app_kwds(cls, config_section, app_name=None):
    kwds = {
        "config_file": None,
        "config_section": config_section,
    }
    uwsgi_opt = uwsgi.opt
    config_file = None
    # check for --set galaxy_config_file=<path>, this overrides whatever config file uWSGI was loaded with (which
    # may not actually include a Galaxy config)
    if uwsgi_opt.get("galaxy_config_file"):
        config_file = uwsgi_opt.get("galaxy_config_file")
    # check for --yaml or --json uWSGI config options next
    if config_file is None:
        config_file = UWSGIApplicationStack._get_config_file(
            uwsgi_opt.get("yaml"), yaml.safe_load, config_section
        ) or UWSGIApplicationStack._get_config_file(
            uwsgi_opt.get("json"), json.load, config_section
        )
    # --ini and --ini-paste don't behave the same way, but this method will only be called by mules if the main
    # application was loaded with --ini-paste, so we can make some assumptions, most notably, uWSGI does not have
    # any way to set the app name when loading with paste.deploy:loadapp(), so hardcoding the alternate section
    # name to `app:main` is fine.
    has_ini_config = (
        config_file is None and uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste")
    )
    has_ini_config = has_ini_config or (
        config_file and has_ext(config_file, "ini", aliases=True, ignore="sample")
    )
    if has_ini_config:
        config_file = config_file or uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste")
        parser = nice_config_parser(config_file)
        if not parser.has_section(config_section) and parser.has_section("app:main"):
            kwds["config_section"] = "app:main"
    kwds["config_file"] = unicodify(config_file)
    return kwds