# Buggy code
def listen(self, events=None, **kwargs):
    # Late import to avoid very expensive in-direct import (~1 second) when this function is
    # not called / used
    from sseclient import SSEClient

    url = self._url
    query_params = {}

    if events and isinstance(events, six.string_types):
        events = [events]

    if "token" in kwargs:
        query_params["x-auth-token"] = kwargs.get("token")

    if "api_key" in kwargs:
        query_params["st2-api-key"] = kwargs.get("api_key")

    if events:
        query_params["events"] = ",".join(events)

    query_string = "?" + urllib.parse.urlencode(query_params)
    url = url + query_string

    for message in SSEClient(url):
        # If the execution on the API server takes too long, the message
        # can be empty. In this case, rerun the query.
        if not message.data:
            continue

        yield json.loads(message.data)


# Traceback (SSLError)
2018-09-25 09:01:02,475  DEBUG - Using cached token from file "/home/ubuntu/.st2/token-st2admin"
Traceback (most recent call last):
  File "/home/ubuntu/st2/st2client/st2client/shell.py", line 402, in run
    func(args)
  File "/home/ubuntu/st2/st2client/st2client/commands/resource.py", line 47, in decorate
    return func(*args, **kwargs)
  File "/home/ubuntu/st2/st2client/st2client/commands/pack.py", line 252, in run_and_print
    instance = super(PackInstallCommand, self).run_and_print(args, **kwargs)
  File "/home/ubuntu/st2/st2client/st2client/commands/resource.py", line 47, in decorate
    return func(*args, **kwargs)
  File "/home/ubuntu/st2/st2client/st2client/commands/pack.py", line 119, in run_and_print
    for event in stream_mgr.listen(events, **kwargs):
  File "/home/ubuntu/st2/st2client/st2client/models/core.py", line 614, in listen
    for message in SSEClient(url):
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/sseclient.py", line 39, in __init__
    self._connect()
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/sseclient.py", line 47, in _connect
    self.resp = requester.get(self.url, stream=True, **self.requests_kwargs)
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/requests-2.14.2-py2.7.egg/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/requests-2.14.2-py2.7.egg/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/requests-2.14.2-py2.7.egg/requests/sessions.py", line 518, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/requests-2.14.2-py2.7.egg/requests/sessions.py", line 639, in send
    r = adapter.send(request, **kwargs)
  File "/home/ubuntu/st2/virtualenv/local/lib/python2.7/site-packages/requests-2.14.2-py2.7.egg/requests/adapters.py", line 512, in send
    raise SSLError(e, request=request)
SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)
# -------- begin 139990567429072 request ----------
curl -X POST -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'User-Agent: python-requests/2.14.2' -H  'content-type: application/json' -H  'X-Auth-Token: 73ea3504cf774a33ad9ac0cd128d3d87' -H  'Content-Length: 18' --data-binary '{"pack": "zabbix"}' http://127.0.0.1:9101/v1/packs/index/search
# -------- begin 139990567429072 response ----------
{
    "name": "zabbix",
    "author": "Hiroyasu OHYAMA",
    "content": {
        "tests": {
            "count": 12,
            "resources": [
                "zabbix_base_action_test_case.py",
                "test_host_get_status.py",
                "test_tool_register_st2_config_to_zabbix.py",
                "test_host_delete.py",
                "test_host_update_status.py",
                "test_maintenance_create_or_update.py",
                "test_maintenance_delete.py",
                "test_test_credentials.py",
                "test_action_base.py",
                "test_host_get_id.py",
                "test_tool_st2_dispatch.py",
                "test_host_get_multiple_ids.py"
            ]
        },
        "actions": {
            "count": 10,
            "resources": [
                "host_update_status",
                "maintenance_delete",
                "host_delete_by_id",
                "test_credentials",
                "host_delete",
                "host_get_status",
                "maintenance_create_or_update",
                "host_get_multiple_ids",
                "ack_event",
                "host_get_id"
            ]
        },
        "triggers": {
            "count": 1,
            "resources": [
                "event_handler"
            ]
        }
    },
    "version": "0.1.7",
    "repo_url": "https://github.com/StackStorm-Exchange/stackstorm-zabbix",
    "keywords": [
        "zabbix",
        "monitoring"
    ],
    "ref": "zabbix",
    "email": "user.localhost2000@gmail.com",
    "description": "StackStorm pack that contains Zabbix integrations"
}
# -------- end 139990567429072 response ------------


For the "zabbix" pack, the following content will be registered:

rules     |  0
sensors   |  0
triggers  |  1
actions   |  10
aliases   |  0

Installation may take a while for packs with many items.
# -------- begin 139990567429072 request ----------
curl -X POST -H  'Connection: keep-alive' -H  'Accept-Encoding: gzip, deflate' -H  'Accept: */*' -H  'User-Agent: python-requests/2.14.2' -H  'content-type: application/json' -H  'X-Auth-Token: 73ea3504cf774a33ad9ac0cd128d3d87' -H  'Content-Length: 55' --data-binary '{"force": false, "python3": false, "packs": ["zabbix"]}' http://127.0.0.1:9101/v1/packs/install
# -------- begin 139990567429072 response ----------
{
    "execution_id": "5ba9f94e987b611744cd4ebf"
}
# -------- end 139990567429072 response ------------

ERROR: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

CLI settings:
----------------
Config file path: /home/ubuntu/.st2/config
Client settings:
----------------
ST2_BASE_URL: http://127.0.0.1
ST2_AUTH_URL: http://127.0.0.1:9100
ST2_API_URL: http://127.0.0.1:9101/v1
ST2_STREAM_URL: https://ubuntu0/stream/v1
ST2_AUTH_TOKEN: 73ea3504cf774a33ad9ac0cd128d3d87

Proxy settings:
---------------
HTTP_PROXY: 
HTTPS_PROXY: 


# Fixed code
def listen(self, events=None, **kwargs):
    # Late import to avoid very expensive in-direct import (~1 second) when this function is
    # not called / used
    from sseclient import SSEClient

    url = self._url
    query_params = {}
    request_params = {}

    if events and isinstance(events, six.string_types):
        events = [events]

    if "token" in kwargs:
        query_params["x-auth-token"] = kwargs.get("token")

    if "api_key" in kwargs:
        query_params["st2-api-key"] = kwargs.get("api_key")

    if events:
        query_params["events"] = ",".join(events)

    if self.cacert is not None:
        request_params["verify"] = self.cacert

    query_string = "?" + urllib.parse.urlencode(query_params)
    url = url + query_string

    for message in SSEClient(url, **request_params):
        # If the execution on the API server takes too long, the message
        # can be empty. In this case, rerun the query.
        if not message.data:
            continue

        yield json.loads(message.data)