# Buggy code
def request_defaults(kwargs):
    hooks = kwargs.pop("hooks", None)
    cookies = kwargs.pop("cookies", None)
    verify = (
        certifi.old_where()
        if all([app.SSL_VERIFY, kwargs.pop("verify", True)])
        else False
    )

    # request session proxies
    if app.PROXY_SETTING:
        logger.debug("Using global proxy: " + app.PROXY_SETTING)
        scheme, address = splittype(app.PROXY_SETTING)
        address = app.PROXY_SETTING if scheme else "http://" + app.PROXY_SETTING
        proxies = {
            "http": address,
            "https": address,
        }
    else:
        proxies = None

    return hooks, cookies, verify, proxies


# 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 request_defaults(kwargs):
    hooks = kwargs.pop("hooks", None)
    cookies = kwargs.pop("cookies", None)
    verify = (
        certifi.old_where()
        if all([app.SSL_VERIFY, kwargs.pop("verify", True)])
        else False
    )

    # Fixes
    # https://github.com/pyca/pyopenssl/pull/209
    # https://github.com/pymedusa/Medusa/issues/1422
    if PY2 and isinstance(verify, text_type):
        verify = filesystem.encode(verify)

    # request session proxies
    if app.PROXY_SETTING:
        logger.debug("Using global proxy: " + app.PROXY_SETTING)
        scheme, address = splittype(app.PROXY_SETTING)
        address = app.PROXY_SETTING if scheme else "http://" + app.PROXY_SETTING
        proxies = {
            "http": address,
            "https": address,
        }
    else:
        proxies = None

    return hooks, cookies, verify, proxies