Unable Python EC2 error: ValueError: JSON object cannot be decoded

I had fun on my way, everything worked, and suddenly I get errors from all my operations with EC2 Ansible (warning about rebuilding was earlier and not a problem):

ec2-user]# ansible -m ping -u ec2-user all /usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability. _warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning) Traceback (most recent call last): File "/root/ansible/bin/ansible", line 194, in <module> (runner, results) = cli.run(options, args) File "/root/ansible/bin/ansible", line 112, in run inventory_manager = inventory.Inventory(options.inventory, vault_password=vault_pass) File "/root/ansible/lib/ansible/inventory/__init__.py", line 118, in __init__ self.parser = InventoryScript(filename=host_list) File "/root/ansible/lib/ansible/inventory/script.py", line 49, in __init__ self.groups = self._parse(stderr) File "/root/ansible/lib/ansible/inventory/script.py", line 57, in _parse self.raw = utils.parse_json(self.data) File "/root/ansible/lib/ansible/utils/__init__.py", line 552, in parse_json results = json.loads(data) File "/usr/lib64/python2.6/json/__init__.py", line 307, in loads return _default_decoder.decode(s) File "/usr/lib64/python2.6/json/decoder.py", line 319, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python2.6/json/decoder.py", line 338, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded 

Does anyone know what gives?

If I try to start the hosts, I get:

  ec2-user]# /etc/ansible/hosts Looks like AWS is down again: EC2ResponseError: 403 Forbidden <?xml version="1.0" encoding="UTF-8"?> <Response><Errors><Error><Code>UnauthorizedOperation</Code><Message>You are not authorized to perform this operation.</Message></Error></Errors><RequestID>9c499f04-3fd8-47cd-a7e4-655af47c1564</RequestID></Response> 

All my actions in the AWS console are still successful.

+5
source share
2 answers

I ran into this problem. It turned out that the problem is related to my AWS keys. Here is what I would suggest:

  • Make sure you have valid keys. I know this seems obvious, but start here :-)
  • If you use export AWS_SECRET_ACCESS_KEY=... to set them in your environment, it is important that the punctuation around them is correct. Mine looks like

export AWS_ACCESS_KEY_ID="ASFSADFSDF" (with quotes)

export AWS_SECRET_ACCESS_KEY=ADSFASFAASFASDFSADSFDASDFSADF (without quotes)

  1. If you install them in .zshconfig or .bash_profile, reload the tab or window to make sure that the configuration file is reread and that your AWS keys are uploaded to the environment.

Hope this helps!

+6
source
  • Make sure you export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. (as others pointed out)
  • Make sure you have boto installed, you can install it by doing:

    sudo pip install boto

+1
source

Source: https://habr.com/ru/post/1208497/


All Articles