AWS CLI: "cannot import name UnrewindableBodyError" - python

I got below error when running 'aws' on a ec2 instance. Any clues what this problem is about?
>>aws configure
Traceback (most recent call last):
File "/bin/aws", line 19, in <module>
import awscli.clidriver
File "/usr/lib/python2.7/site-packages/awscli/clidriver.py", line 17, in <module>
import botocore.session
File "/usr/lib/python2.7/site-packages/botocore/session.py", line 27, in <module>
import botocore.configloader
File "/usr/lib/python2.7/site-packages/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/usr/lib/python2.7/site-packages/botocore/compat.py", line 26, in <module>
from urllib3 import exceptions
File "/usr/lib/python2.7/site-packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 31, in <module>
from .connection import (
File "/usr/lib/python2.7/site-packages/urllib3/connection.py", line 45, in <module>
from .util.ssl_ import (
File "/usr/lib/python2.7/site-packages/urllib3/util/__init__.py", line 4, in <module>
from .request import make_headers
File "/usr/lib/python2.7/site-packages/urllib3/util/request.py", line 5, in <module>
from ..exceptions import UnrewindableBodyError
ImportError: cannot import name UnrewindableBodyError

In order to install aws cli on rhel 8 follow these steps
install python3-pip
pip3 install awscli --upgrade --user
confirm it by this
aws --version
if you want to check out docs on installation.
However my recommendation will be to NOT store your aws credentials ( programmatic key) within your instance because if by any chance your instance is compromised so does your account too, or if instance is shared among other users, they will get access to your creds.
if it was local or personal computer i would have recommended to go with aws configure command but since its not, the best practice will be to
create IAM role,give permission according to your use case, and attach that role to your ec2 instance and then run aws cli commands.

Related

Gcloud sdk install for Mac

I have an issue to install the gcloud sdk on my mac. I have the following error when I do the ./install.sh. Source: https://cloud.google.com/sdk/docs/quickstart
Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File "/Users/kevin/Downloads/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
import bootstrapping
File "/Users/kevin/Downloads/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
import setup # pylint:disable=g-import-not-at-top
File "/Users/kevin/Downloads/google-cloud-sdk/bin/bootstrapping/setup.py", line 57, in <module>
from googlecloudsdk.core.util import platforms
File "/Users/kevin/Downloads/google-cloud-sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/Users/kevin/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/re.py", line 124, in <module>
import enum
File "/Users/kevin/Downloads/google-cloud-sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
And when I do gcloud init
Traceback (most recent call last):
File "/Users/kevin/Downloads/google-cloud-sdk/lib/gcloud.py", line 104, in <module>
main()
File "/Users/kevin/Downloads/google-cloud-sdk/lib/gcloud.py", line 62, in main
from googlecloudsdk.core.util import encoding
File "/Users/kevin/Downloads/google-cloud-sdk/lib/googlecloudsdk/__init__.py", line 23, in <module>
from googlecloudsdk.core.util import importing
File "/Users/kevin/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/util/importing.py", line 23, in <module>
import imp
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/imp.py", line 23, in <module>
from importlib import util
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/importlib/util.py", line 2, in <module>
from . import abc
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/importlib/abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/typing.py", line 26, in <module>
import re as stdlib_re # Avoid confusion with the re we export.
File "/Users/kevin/.pyenv/versions/3.9.0/lib/python3.9/re.py", line 124, in <module>
import enum
File "/Users/kevin/Downloads/google-cloud-sdk/lib/third_party/enum/__init__.py", line 26, in <module>
spec = importlib.util.find_spec('enum')
AttributeError: module 'importlib' has no attribute 'util'
I think this is a Python issue. but I'm running Python3:
python -V shows
Python 3.9.0
I have installed it with homebrew.
What can be the problem?
This is a known issue across Mac, Windows and Linux: https://issuetracker.google.com/170125513.
I'd suggest to use the recommended Python versions mentioned here (3.5 to 3.8).
Also this does not affect only to Cloud SDK but others as well (for example as mentioned here).
Thanks for your answer. Indeed, it works with the version 3.8.6 of python.
I will add some infos if it can help somebody. In order to manage python version, I have used pyenv and installed the version of python I needed.
pyenv install 3.8.6
pyenv global 3.8.6
If you want a quick fix you can add this to your bash profile and restart your terminal:
export CLOUDSDK_PYTHON=python3.8
Worked for me

Unable to run AWS CLI: ImportError: cannot import name 'HTTPClientError'

I recently tried to install some Python Packages (Superset, Bonobo amongst others) after which my AWS cli stopped working with the below issue:
user#ubuntu-machine:~$ aws --version
Traceback (most recent call last):
File "/home/user/.local/bin/aws", line 27, in <module>
sys.exit(main())
File "/home/user/.local/bin/aws", line 23, in main
return awscli.clidriver.main()
File "/home/user/.local/lib/python3.6/site-packages/awscli/clidriver.py", line 58, in main
driver = create_clidriver()
File "/home/user/.local/lib/python3.6/site-packages/awscli/clidriver.py", line 68, in create_clidriver
event_hooks=session.get_component('event_emitter'))
File "/home/user/.local/lib/python3.6/site-packages/awscli/plugin.py", line 44, in load_plugins
modules = _import_plugins(plugin_mapping)
File "/home/user/.local/lib/python3.6/site-packages/awscli/plugin.py", line 61, in _import_plugins
module = __import__(path, fromlist=[module])
File "/home/user/.local/lib/python3.6/site-packages/awscli/handlers.py", line 20, in <module>
from awscli.paramfile import register_uri_param_handler
File "/home/user/.local/lib/python3.6/site-packages/awscli/paramfile.py", line 18, in <module>
from botocore.httpsession import URLLib3Session
File "/home/user/.local/lib/python3.6/site-packages/botocore/httpsession.py", line 24, in <module>
from botocore.exceptions import (
ImportError: cannot import name 'HTTPClientError'
Inorder to restore it I've tried un-installing all packages mentioned in What is the easiest way to remove all packages installed by pip?, and only reinstalled awscli. Still I run into the same issue.
Did you uninstall botocore as well before you uninstall and reinstall the aws cli? Sometime you can get in this situation as when you install other packages it relies on different version of botocore and conflict with the one that aws cli needs. In these situations I think you want to use python virtual environment for your project to keep your project dependencies isolate from the global python environment which is where aws cli botocore resides.

Error Importing Pyro after source install for Anaconda release of Python

I downloaded Pyro using source install instructions here under the Install from source link because I was always told not to use pip when installing to an Anaconda installation. When I try import pyro I get the attribute error below which does not make sense
import pyro
Traceback (most recent call last):
File "<ipython-input-48-05a8cb49cc0d>", line 1, in <module>
import pyro
File "C:\Users\bjwil\Anaconda3\Lib\site-packages\pyro\__init__.py", line 6, in <module>
from pyro.primitives import (clear_param_store, enable_validation, get_param_store, iarange, irange, module, param,
File "C:\Users\bjwil\Anaconda3\Lib\site-packages\pyro\primitives.py", line 10, in <module>
import pyro.infer as infer
File "C:\Users\bjwil\Anaconda3\Lib\site-packages\pyro\infer\__init__.py", line 14, in <module>
from pyro.infer.traceenum_elbo import JitTraceEnum_ELBO, TraceEnum_ELBO
File "C:\Users\bjwil\Anaconda3\Lib\site-packages\pyro\infer\traceenum_elbo.py", line 183, in <module>
class BackwardSampleMessenger(pyro.poutine.messenger.Messenger):
AttributeError: module 'pyro.poutine' has no attribute 'messenger'
This doesn't make much sense because in the poutine folder I have the messenger file and it has the Class Messenger so line 183 class BackwardSampleMessenger(pyro.poutine.messenger.Messenger) in the traceenum_elbo.py file should be working.

ImportError: cannot import name FileModeWarning

I have set up an all in one swift. While setting up keystone in all-in-one-swift I am having an error when I try to create the service entity and API endpoints. I followed liberty documentation but couldn't resolve this issue!
Documentation link
[root#arupsaio ~]# openstack service create --name keystone --description "OpenStack Identity" identity
Traceback (most recent call last):
File "/usr/bin/openstack", line 6, in <module>
from openstackclient.shell import main
File "/usr/lib/python2.7/site-packages/openstackclient/shell.py", line 30, in <module>
from openstackclient.common import clientmanager
File "/usr/lib/python2.7/site-packages/openstackclient/common/clientmanager.py", line 23, in <module>
import requests
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
from . import utils
File "/usr/lib/python2.7/site-packages/requests/utils.py", line 32, in <module>
from .exceptions import InvalidURL, FileModeWarning
ImportError: cannot import name FileModeWarning
In my case, there were some package leftovers.
I had to uninstall the package 3 times!
pip uninstall requests # x3
And then reinstall the new version
pip install requests

py2neo offline install failing

I'm trying to install py2neo on an offline machine. I can't use pip because I'm not connected to the internet. I'm trying to install py2neo-2.0.3 with python2.7.9 on redhat. When I run python setup.py install I get ImportError: cannot import name HTTPSConnection.
Traceback (most recent call last):
File "setup.py", line 29, in <module>
from py2neo import __author__, __email__, __license__, __package__, __version__
File "usr/lib/py2neo-2.0.3/py2neo/__init__.py" line 27, in <module>
from py2neo.core import *
File "usr/lib/py2neo-2.0.3/py2neo/core.py", line 28, in <module>
from py2neo.env import NEO4J_AUTH_TOKEN, NEO4J_URI
File "usr/lib/py2neo-2.0.3/py2neo/env.py", line 21, in <module>
from py2neo.packages.httpstream.packages.urimagic import URI
File "usr/lib/py2neo-2.0.3/py2neo/packages/httpstream/__init__.py", line 32, in <module>
from .http import *
File "usr/lib/py2neo-2.0.3/py2neo/packages/httpstream/http.py", line 31, in <module>
from httplib import (BadStatusLine, CannotSendRequest,
ImportError: cannot import name HTTPSConnection
I've tried installing httpstream but that didn't fix the import error.
HTTPSConnection should come with the standard library and isn't part of py2neo itself:
https://docs.python.org/2/library/httplib.html#httplib.HTTPSConnection
I don't know specifically about how RedHat package Python but it's possible you need to install SSL support in addition to the main language. I believe this is a separate compilation option:
http://www.webtop.com.au/blog/compiling-python-with-ssl-support-fedora-10-2009020237

Categories