Details
-
Bug
-
Resolution: Fixed
-
Major
-
None
-
None
-
DOC-2021-Sep12-S18, DOC-2021-Sep26-S19, DOC-2021-Oct10-S20, DOC-2021-Oct24-S21, DOC-2021-Nov07-S22, DOC-2021-Nov21-S23, DOC-2021-Dec05-S24
-
1
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)
|