# Buggy code
def _handle_output(result):
    """Convert result to unicode."""
    if not result:
        return result

    if isinstance(result, binary_type):
        # on windows the returned info from fs operations needs to be decoded using fs encoding
        return text_type(result, "utf-8" if os.name != "nt" else fs_encoding)

    if isinstance(result, list) or isinstance(result, tuple):
        return map(_handle_output, result)

    if isinstance(result, dict):
        for k, v in result.items():
            result[k] = _handle_output(v)
        return result

    return result


# Traceback (TypeError)
2016-11-01 03:00:02 ERROR    SHOWUPDATER :: [e372494] Exception generated in thread SHOWUPDATER: cafile must be None or a byte string
Traceback (most recent call last):
File "/media/sdq1/home/**********/.sickrage/medusa/scheduler.py", line 103, in run
self.action.run(self.force)
File "/media/sdq1/home/**********/.sickrage/medusa/show_updater.py", line 68, in run
t = app.indexerApi(indexer).indexer(**indexer_api_params)
File "/media/sdq1/home/**********/.sickrage/medusa/indexers/indexer_api.py", line 34, in indexer
return indexerConfig[self.indexer_id]['module'](*args, **kwargs)
File "/media/sdq1/home/**********/.sickrage/medusa/indexers/tvdbv2/tvdbv2_api.py", line 66, in __init__
access_token = auth_api.login_post(authentication_string)
File "/media/sdq1/home/**********/.sickrage/lib/tvdbapiv2/apis/authentication_api.py", line 124, in login_post
callback=params.get('callback'))
File "/media/sdq1/home/**********/.sickrage/lib/tvdbapiv2/api_client.py", line 324, in call_api
response_type, auth_settings, callback)
File "/media/sdq1/home/**********/.sickrage/lib/tvdbapiv2/api_client.py", line 150, in __call_api
post_params=post_params, body=body)
File "/media/sdq1/home/**********/.sickrage/lib/tvdbapiv2/api_client.py", line 360, in request
body=body)
File "/media/sdq1/home/**********/.sickrage/lib/tvdbapiv2/rest.py", line 208, in POST
body=body)
File "/media/sdq1/home/**********/.sickrage/lib/tvdbapiv2/rest.py", line 143, in request
headers=headers)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/request.py", line 73, in request
**urlopen_kw)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/request.py", line 151, in request_encode_body
return self.urlopen(method, url, **extra_kw)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/poolmanager.py", line 165, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/connectionpool.py", line 578, in urlopen
chunked=chunked)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/connectionpool.py", line 351, in _make_request
self._validate_conn(conn)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/connectionpool.py", line 814, in _validate_conn
conn.connect()
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/connection.py", line 289, in connect
ssl_version=resolved_ssl_version)
File "/media/sdq1/home/**********/.sickrage/lib/requests/packages/urllib3/contrib/pyopenssl.py", line 328, in ssl_wrap_socket
ctx.load_verify_locations(ca_certs, ca_cert_dir)
File "/usr/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 303, in load_verify_locations
raise TypeError("cafile must be None or a byte string")
TypeError: cafile must be None or a byte string

# Fixed code
def _handle_output(result):
    """Convert result to unicode."""
    if not result:
        return result

    if isinstance(result, binary_type):
        # on windows the returned info from fs operations needs to be decoded using fs encoding
        return decode(result)

    if isinstance(result, list) or isinstance(result, tuple):
        return map(_handle_output, result)

    if isinstance(result, dict):
        for k, v in result.items():
            result[k] = _handle_output(v)
        return result

    return result