print("------------------------------------------------------------------------")
print("--- List Products and get actual price")
print("------------------------------------------------------------------------")
sleep(1)
path = "/api/v3/brokerage/products?product_ids=BTC-EUR&product_ids=ETH-EUR"
method = "GET"
payload = ''
# Generate timestamp
timestamp = str(int(time.time()))
message = timestamp + method + path + payload
signature = hmac.new(SECRET_KEY.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()
# Set headers
headers = {
"accept": "application/json",
"CB-ACCESS-KEY": ACCESS_KEY,
"CB-ACCESS-SIGN": signature,
"CB-ACCESS-TIMESTAMP": timestamp
}
# Send request
conn.request(method, path, payload, headers)
# Get response
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
# Print response
result = json.loads(data)
json_formatted_str = json.dumps(result, indent=2)
print(json_formatted_str)
#print(result)
This is the result:
------------------------------------------------------------------------
--- List Products and get actual price
------------------------------------------------------------------------
Unauthorized
Traceback (most recent call last):
File "/var/www/html/coinbase/advanced/test2.py", line 124, in <module>
result = json.loads(data)
File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I see “Unauthorized” but other queries like “Get Account” works fine.