Handles BasicAuth preparation and error handling.  Either both
        ``username`` and ``password`` must be defined, or neither.  Defining
        one but not the other will result in an :class:`AssertionError`.

        ``username``
        ``password``

        Returns a tuple of ``(header_key, header_value)`` which can be inserted
        into the headers dictionary.

def _prepare_basicauth(self, username, password):
        """
        Handles BasicAuth preparation and error handling.  Either both
        ``username`` and ``password`` must be defined, or neither.  Defining
        one but not the other will result in an :class:`AssertionError`.

        ``username``
        ``password``

        Returns a tuple of ``(header_key, header_value)`` which can be inserted
        into the headers dictionary.
        """
        if username and password:
            enc_str = base64.b64encode(":".join((username, password)))
            return ("Authorization", "Basic %s" % enc_str)
        elif username or password:
            raise Exception("Username and password must both be specified.")
        else:
            return None