While trying to debug patroni connection to consul, I tried to write simple python connector to consul myself.

That's what I'm doing(python3, Centos7)

import consul
c = consul.Consul(host='consul-host',port=port,token='some-token')

That's what I'm getting(same error as patroni produces):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/consul/base.py", line 554, in get
  File "/usr/local/lib/python3.6/site-packages/consul/std.py", line 22, in get
    self.session.get(uri, verify=self.verify, cert=self.cert)))
  File "/usr/local/lib/python3.6/site-packages/consul/base.py", line 223, in cb
    CB._status(response, allow_404=allow_404)
  File "/usr/local/lib/python3.6/site-packages/consul/base.py", line 181, in _status
    raise ACLPermissionDenied(response.body)
consul.base.ACLPermissionDenied: rpc error making call: Permission denied

Curl works fine with that token.

curl --header "X-Consul-Token:some-token" http://consul-host:port/v1/kv/some/long/path/bar | jq .

    "LockIndex": 0,
    "Key": "/v1/kv/some/long/path/bar",
    "Flags": 0,
    "Value": "Zm9v",
    "CreateIndex": 2951475,
    "ModifyIndex": 2951475

Any ideas on what am I doing wrong? Thanks.


Your traceback is pointing to consul/base.py:554:

return self.agent.http.get(
    CB.json(index=True, decode=decode, one=one),
    '/v1/kv/%s' % key,

Since you're passing key '/v1/kv/some/long/path/bar' it will hit endpoint http://consul-host:port/v1/kv/v1/kv/some/long/path/bar and not http://consul-host:port/v1/kv/some/long/path/bar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.