# Buggy code
def request_minion_cachedir(
    minion_id,
    opts=None,
    fingerprint="",
    pubkey=None,
    provider=None,
    base=None,
):
    """
    Creates an entry in the requested/ cachedir. This means that Salt Cloud has
    made a request to a cloud provider to create an instance, but it has not
    yet verified that the instance properly exists.

    If the fingerprint is unknown, a raw pubkey can be passed in, and a
    fingerprint will be calculated. If both are empty, then the fingerprint
    will be set to None.
    """
    if base is None:
        base = __opts__["cachedir"]

    if not fingerprint and pubkey is not None:
        fingerprint = salt.utils.pem_finger(
            key=pubkey, sum_type=(opts and opts.get("hash_type") or "sha256")
        )

    init_cachedir(base)

    data = {
        "minion_id": minion_id,
        "fingerprint": fingerprint,
        "provider": provider,
    }

    fname = "{0}.p".format(minion_id)
    path = os.path.join(base, "requested", fname)
    with salt.utils.fopen(path, "w") as fh_:
        msgpack.dump(data, fh_)


# Traceback (TypeError)
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
TypeError: a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "/home/bar/Dev/foo/build7/_venv/bin/salt-ssh", line 11, in <module>
load_entry_point('salt==2017.7.2', 'console_scripts', 'salt-ssh')()
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/scripts.py", line 416, in salt_ssh
client.run()
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/cli/ssh.py", line 20, in run
ssh = salt.client.ssh.SSH(self.config)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/client/ssh/__init__.py", line 230, in __init__
self.tgt_type)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/roster/__init__.py", line 105, in targets
targets.update(self.rosters[f_str](tgt, tgt_type))
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/roster/cloud.py", line 45, in targets
minions = __runner__['cache.cloud'](tgt)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/runners/cache.py", line 402, in cloud
cloud_cache = __utils__['cloud.list_cache_nodes_full'](opts=opts, provider=provider)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/utils/cloud.py", line 2768, in list_cache_nodes_full
minions[driver][prov][minion_id] = msgpack.load(fh_)
File "msgpack/_unpacker.pyx", line 164, in msgpack._unpacker.unpack (msgpack/_unpacker.cpp:2622)
File "msgpack/_unpacker.pyx", line 124, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:1918)
TypeError: a bytes-like object is required, not 'str'
Traceback (most recent call last):
File "/home/bar/Dev/foo/build7/_venv/bin/salt-ssh", line 11, in <module>
load_entry_point('salt==2017.7.2', 'console_scripts', 'salt-ssh')()
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/scripts.py", line 416, in salt_ssh
client.run()
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/cli/ssh.py", line 20, in run
ssh = salt.client.ssh.SSH(self.config)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/client/ssh/__init__.py", line 230, in __init__
self.tgt_type)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/roster/__init__.py", line 105, in targets
targets.update(self.rosters[f_str](tgt, tgt_type))
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/roster/cloud.py", line 45, in targets
minions = __runner__['cache.cloud'](tgt)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/runners/cache.py", line 402, in cloud
cloud_cache = __utils__['cloud.list_cache_nodes_full'](opts=opts, provider=provider)
File "/home/bar/Dev/foo/build7/_venv/lib/python3.5/site-packages/salt/utils/cloud.py", line 2768, in list_cache_nodes_full
minions[driver][prov][minion_id] = msgpack.load(fh_)
File "msgpack/_unpacker.pyx", line 164, in msgpack._unpacker.unpack (msgpack/_unpacker.cpp:2622)
File "msgpack/_unpacker.pyx", line 124, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:1918)
TypeError: a bytes-like object is required, not 'str'
EXIT 1

# Fixed code
def request_minion_cachedir(
    minion_id,
    opts=None,
    fingerprint="",
    pubkey=None,
    provider=None,
    base=None,
):
    """
    Creates an entry in the requested/ cachedir. This means that Salt Cloud has
    made a request to a cloud provider to create an instance, but it has not
    yet verified that the instance properly exists.

    If the fingerprint is unknown, a raw pubkey can be passed in, and a
    fingerprint will be calculated. If both are empty, then the fingerprint
    will be set to None.
    """
    if base is None:
        base = __opts__["cachedir"]

    if not fingerprint and pubkey is not None:
        fingerprint = salt.utils.pem_finger(
            key=pubkey, sum_type=(opts and opts.get("hash_type") or "sha256")
        )

    init_cachedir(base)

    data = {
        "minion_id": minion_id,
        "fingerprint": fingerprint,
        "provider": provider,
    }

    fname = "{0}.p".format(minion_id)
    path = os.path.join(base, "requested", fname)
    mode = "wb" if six.PY3 else "w"
    with salt.utils.fopen(path, mode) as fh_:
        msgpack.dump(data, fh_)