# Buggy code
def _get_artifact_metadata_xml(
    artifactory_url, repository, group_id, artifact_id, headers
):
    artifact_metadata_url = _get_artifact_metadata_url(
        artifactory_url=artifactory_url,
        repository=repository,
        group_id=group_id,
        artifact_id=artifact_id,
    )
    try:
        request = urllib.request.Request(artifact_metadata_url, None, headers)
        artifact_metadata_xml = urllib.request.urlopen(request).read()
    except HTTPError as http_error:
        message = "Could not fetch data from url: {url}, HTTPError: {error}"
        raise Exception(message.format(url=artifact_metadata_url, error=http_error))

    log.debug("artifact_metadata_xml=%s", artifact_metadata_xml)
    return artifact_metadata_xml


# Traceback (TypeError)
.. versionadded:: 2015.5.0

This function will call :mod:`state.highstate
<salt.modules.state.highstate>` or :mod:`state.sls
<salt.modules.state.sls>` based on the arguments passed to this function.
It exists as a more intuitive way of applying states.

.. rubric:: APPLYING ALL STATES CONFIGURED IN TOP.SLS (A.K.A. :ref:`HIGHSTATE <running-highstate>`)

To apply all configured states, simply run ``state.apply``:

.. code-block:: bash

salt '*' state.apply

The following additional arguments are also accepted when applying all
states configured in top.sls:

test
Run states in test-only (dry-run) mode

pillar
Custom Pillar values, passed as a dictionary of key-value pairs

.. code-block:: bash

salt '*' state.apply test pillar='{"foo": "bar"}'

.. note::
Values passed this way will override Pillar values set via
``pillar_roots`` or an external Pillar source.

queue : False
Instead of failing immediately when another state run is in progress,
queue the new state run to begin running once the other has finished.

This option starts a new thread for each queued state run, so use this
option sparingly.

localconfig
Optionally, instead of using the minion config, load minion opts from
the file specified by this argument, and then merge them with the
options from the minion config. This functionality allows for specific
states to be run with their own custom minion configuration, including
different pillars, file_roots, etc.

.. code-block:: bash

salt '*' state.apply localconfig=/path/to/minion.yml


.. rubric:: APPLYING INDIVIDUAL SLS FILES (A.K.A. :py:func:`STATE.SLS <salt.modules.state.sls>`)

To apply individual SLS files, pass them as a comma-separated list:

.. code-block:: bash

# Run the states configured in salt://test.sls (or salt://test/init.sls)
salt '*' state.apply test
# Run the states configured in salt://test.sls (or salt://test/init.sls)
# and salt://pkgs.sls (or salt://pkgs/init.sls).
salt '*' state.apply test,pkgs

The following additional arguments are also accepted when applying
individual SLS files:

test
Run states in test-only (dry-run) mode

pillar
Custom Pillar values, passed as a dictionary of key-value pairs

.. code-block:: bash

salt '*' state.apply test pillar='{"foo": "bar"}'

.. note::
Values passed this way will override Pillar values set via
``pillar_roots`` or an external Pillar source.

queue : False
Instead of failing immediately when another state run is in progress,
queue the new state run to begin running once the other has finished.

This option starts a new thread for each queued state run, so use this
option sparingly.

concurrent : False
Execute state runs concurrently instead of serially

.. warning::

This flag is potentially dangerous. It is designed for use when
multiple state runs can safely be run at the same time. Do *not*
use this flag for performance optimization.

saltenv : None
Specify a salt fileserver environment to be used when applying states

.. versionchanged:: 0.17.0
Argument name changed from ``env`` to ``saltenv``

.. versionchanged:: 2014.7.0
If no saltenv is specified, the minion config will be checked for a
``saltenv`` parameter and if found, it will be used. If none is
found, ``base`` will be used. In prior releases, the minion config
was not checked and ``base`` would always be assumed when the
saltenv was not explicitly set.

pillarenv
Specify a Pillar environment to be used when applying states. By
default, all Pillar environments will be merged together and used.

localconfig
Optionally, instead of using the minion config, load minion opts from
the file specified by this argument, and then merge them with the
options from the minion config. This functionality allows for specific
states to be run with their own custom minion configuration, including
different pillars, file_roots, etc.

.. code-block:: bash

salt '*' state.apply test localconfig=/path/to/minion.yml

Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/salt/minion.py", line 1332, in _thread_return
return_data = executor.execute()
File "/usr/lib/python2.6/site-packages/salt/executors/direct_call.py", line 28, in execute
return self.func(*self.args, **self.kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/state.py", line 455, in apply_
return sls(mods, **kwargs)
File "/usr/lib/python2.6/site-packages/salt/modules/state.py", line 954, in sls
serial.dump(ret, fp_)
File "/usr/lib/python2.6/site-packages/salt/payload.py", line 226, in dump
fn_.write(self.dumps(msg))
File "/usr/lib/python2.6/site-packages/salt/payload.py", line 141, in dumps
return msgpack.dumps(msg)
File "/usr/lib64/python2.6/site-packages/msgpack/__init__.py", line 47, in packb
return Packer(**kwargs).pack(o)
File "msgpack/_packer.pyx", line 223, in msgpack._packer.Packer.pack (msgpack/_packer.cpp:223)
File "msgpack/_packer.pyx", line 225, in msgpack._packer.Packer.pack (msgpack/_packer.cpp:225)
File "msgpack/_packer.pyx", line 184, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:184)
File "msgpack/_packer.pyx", line 184, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:184)
File "msgpack/_packer.pyx", line 220, in msgpack._packer.Packer._pack (msgpack/_packer.cpp:220)
TypeError: can't serialize URLError(error(110, 'Connection timed out'),)

# Fixed code
def _get_artifact_metadata_xml(
    artifactory_url, repository, group_id, artifact_id, headers
):
    artifact_metadata_url = _get_artifact_metadata_url(
        artifactory_url=artifactory_url,
        repository=repository,
        group_id=group_id,
        artifact_id=artifact_id,
    )

    try:
        request = urllib.request.Request(artifact_metadata_url, None, headers)
        artifact_metadata_xml = urllib.request.urlopen(request).read()
    except (HTTPError, URLError) as err:
        message = "Could not fetch data from url: {0}. ERROR: {1}".format(
            artifact_metadata_url, err
        )
        raise CommandExecutionError(message)

    log.debug("artifact_metadata_xml=%s", artifact_metadata_xml)
    return artifact_metadata_xml