Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-8595

CBC Cloud API python 3 header example code issues

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • None
    • None
    • cloud

    Description

      https://docs.couchbase.com/cloud/public-api-guide/using-cloud-public-api.html#header-values

      The sample code shown after this line has syntax errors and is incomplete. "To show how the Base 64 encoded Hmac sha256 hash is calculated, here’s an example using Python 3."

      This line has spurious single quotes after the variable cbc_api_signature:

      cbc_api_signature'' = base64.b64encode(hmac.new(bytes(cbc_secret_key, 'utf-8'), bytes(cbc_api_message,'utf-8'), digestmod=hashlib.sha256).digest())
      

      I couldn't run the code without importing dependencies it uses, we should add the following to the top of the file.

      import base64
      import datetime
      import hashlib
      import hmac
      

      It's also using a variable with the wrong name
      The line

      cbc_api_secret_key = ‘my secret key’
      

      should read

      cbc_secret_key = ‘my secret key’
      

      And it is using a variable that's not defined.
      Need to add this line after the cbc_secret_key line.

      cbc_access_key = 'my access key'
      

      We may also want to show that the code is outputting the required header with a print statement at the last line.

      print (cbc_api_request_headers)
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            richard.smedley Richard Smedley
            ianmccloy Ian McCloy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty