code: def _prepare_basicauth(self, username, password):
          
          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
docs: 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.