code: def sign(self, request, authheaders, secret):
          
          if "id" not in authheaders or authheaders["id"] == '':
              raise KeyError("id required in authorization headers.")
          if "nonce" not in authheaders or authheaders["nonce"] == '':
              raise KeyError("nonce required in authorization headers.")
          if "realm" not in authheaders or authheaders["realm"] == '':
              raise KeyError("realm required in authorization headers.")
          if request.get_header('x-authorization-timestamp') == '':
              raise KeyError("X-Authorization-Timestamp is required.")
          bodyhash = None
          if request.body is not None and request.body != b'':
              sha256 = hashlib.sha256()
              sha256.update(request.body)
              bodyhash = base64.b64encode(sha256.digest()).decode('utf-8')
  
          try:
              mac = hmac.HMAC(base64.b64decode(secret.encode('utf-8'), validate=True), digestmod=self.digest)
          except TypeError:
              s = secret.encode('utf-8')
              if not re.match(b'^[A-Za-z0-9+/]*={0,2}$', s):
                  raise binascii.Error('Non-base64 digit found')
              mac = hmac.HMAC(base64.b64decode(s), digestmod=self.digest)
          mac.update(self.signable(request, authheaders, bodyhash).encode('utf-8'))
          digest = mac.digest()
          return base64.b64encode(digest).decode('utf-8')
docs: Returns the v2 signature appropriate for the request. The request is not changed by this function.
  
          Keyword arguments:
          request -- A request object which can be consumed by this API.
          authheaders -- A string-indexable object which contains the headers appropriate for this signature version.
          secret -- The base64-encoded secret key for the HMAC authorization.