Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No JSON object could be decoded" when writing to KV v2 #293

Open
justyns opened this issue Oct 16, 2018 · 2 comments · May be fixed by #898
Open

"No JSON object could be decoded" when writing to KV v2 #293

justyns opened this issue Oct 16, 2018 · 2 comments · May be fixed by #898
Labels
enhancement a new feature or addition kv Key/Value (KV) secrets engine

Comments

@justyns
Copy link

justyns commented Oct 16, 2018

Versions

  • hvac==0.6.4
  • Vault v0.11.1 ('8575f8fedcf8f5a6eb2b4701cb527b99574b5286')

Problem

I'm currently running into a weird issue where I am attempting to write secrets to the kv v2 api, and it is returning an error.

Example script

This is an example of what I'm doing:

import os
import hvac

vault_url = os.environ.get('VAULT_ADDR', 'http:https://127.0.0.1:8200')
vault_token = os.environ.get('VAULT_TOKEN')
vault_secret_prefix = 'test/demoapp/'

client = hvac.Client(url=vault_url, token=vault_token)

kv = client.kv.v2
kv.create_or_update_secret(
    path="{}secret2".format(vault_secret_prefix),
    secret=dict(foo='bar'))

Error

And this is the error:

Traceback (most recent call last):
  File "hvac-test.py", line 31, in <module>
    secret=dict(foo='bar'))
  File "/usr/local/lib/python2.7/site-packages/hvac/api/secrets_engines/kv_v2.py", line 124, in create_or_update_secret
    return response.json()
  File "/usr/local/lib/python2.7/site-packages/requests/models.py", line 896, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Additional information

https://github.com/hvac/hvac/blob/master/hvac/api/secrets_engines/kv_v2.py#L124 looks like it always returns response.json() but after adding some debug statements to that function, the response from vault is a 204 and there's no data to parse.

Sidenote: The above error is from running vault in server mode. I tested using dev mode, and I do not get the same error. I haven't investigated why, but vault in dev mode apparently returns a response (with a 200 instead of 204) when it does not without dev mode. I might open a ticket on the vault repo for this if the docs don't mention it.

@justyns
Copy link
Author

justyns commented Oct 16, 2018

Update: This was my fault.. When you run vault in dev mode, it automatically enables V2 of the kv at /secret. I assumed the real server was also doing this, but the default behavior for that is to use v1 instead of v1.

I enabled versioning / kv v2 on the real server and it worked as expected.

Should I leave this open? I feel like there could at least be a better error message for this situation.

@jeffwecan jeffwecan added enhancement a new feature or addition kv Key/Value (KV) secrets engine labels Oct 17, 2018
@jeffwecan
Copy link
Member

@justyns: Totally agree that the exception raised in this case makes things more confusing than need be. Will see what we can do about raising a more helpful message in these cases... 👍

@jeffwecan jeffwecan added this to the 0.7.1 milestone Nov 1, 2018
@jeffwecan jeffwecan modified the milestones: 0.7.1, 0.7.2 Dec 19, 2018
@jeffwecan jeffwecan modified the milestones: 0.7.2, 0.7.3 Jan 1, 2019
@jeffwecan jeffwecan added this to Needs triage in Bug / Feature Request Triage via automation Jan 18, 2019
@jeffwecan jeffwecan moved this from Needs triage to High priority in Bug / Feature Request Triage Jan 18, 2019
@jeffwecan jeffwecan modified the milestones: 0.8.0, 0.8.1 Mar 29, 2019
@jeffwecan jeffwecan modified the milestones: 0.8.3, 0.8.4 May 18, 2019
@jeffwecan jeffwecan modified the milestones: 0.9.1, 0.9.2 May 25, 2019
@jeffwecan jeffwecan removed this from the 0.9.2 milestone Jun 8, 2019
@briantist briantist linked a pull request Sep 18, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a new feature or addition kv Key/Value (KV) secrets engine
Projects
2 participants