ImportError: cannot import name FileModeWarning - python

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

Related

AWS CLI: "cannot import name UnrewindableBodyError"

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.

ImportError: cannot import name 'UserAgentMixin'

I've got an issue when I want to init my Flask DB, here is Terminal result :
user#Pc:~/Documents/test$ flask db init
Traceback (most recent call last):
File "/home/user/.local/bin/flask", line 7, in <module>
from flask.cli import main
File "/home/user/.local/lib/python3.6/site-packages/flask/__init__.py", line 17, in <module>
from werkzeug.exceptions import abort
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/__init__.py", line 151, in <module>
__import__('werkzeug.exceptions')
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/exceptions.py", line 71, in <module>
from werkzeug.wrappers import Response
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/__init__.py", line 30, in <module>
from .request import PlainRequest
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/request.py", line 6, in <module>
from .user_agent import UserAgentMixin
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/wrappers/user_agent.py", line 1, in <module>
from ..useragents import UserAgent
File "/home/user/.local/lib/python3.6/site-packages/werkzeug/useragents.py", line 212, in <module>
from werkzeug.wrappers import UserAgentMixin # noqa
ImportError: cannot import name 'UserAgentMixin'
I'm working on an Ubuntu 18.04 LTS, using Flask, SQLAlchemy, Python and PostgreSQL. From where does this error occurs, and how can I solve it?
P.S : I followed the mega tutorial about Flask
EDIT 1 : Werkzeug is already installed
(venv) user#Pc:~/Documents/test$ pip install Werkzeug
Requirement already satisfied: Werkzeug in ./venv/lib/python3.6/site-packages
EDIT 2 : I don't know why I got this issue, but this error disappear after I removed spaces indentations
Try pip install Werkzeug
UserAgentMixin is from werkzeug!
ref: https://tedboy.github.io/flask/generated/generated/werkzeug.UserAgentMixin.html
in my case, I found a file and a folder, both named "wrappers" in the package path, so I reinstall the package:
pip uninstall Werkzeug
pip install Werkzeug
though a little late, it may still help

Tweepy installation?

I tried to install tweepy by using different methods such as
pip install tweepy
sudo pip install tweepy
Lastly, i downloaded zip package from the github and used the command to install:
python setup.py install
Apparently, installation was completed successfully, however when i run a simple program which contains only one line such as import tweepy, the following error is thrown:
Traceback (most recent call last):
File "tweepytest.py", line 1, in <module>
import tweepy
File "build/bdist.macosx-10.6-intel/egg/tweepy/__init__.py", line 14, in <module>
File "build/bdist.macosx-10.6-intel/egg/tweepy/api.py", line 12, in <module>
File "build/bdist.macosx-10.6-intel/egg/tweepy/binder.py", line 11, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 33, in <module>
from .packages.ssl_match_hostname import CertificateError
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/packages/__init__.py", line 3, in <module>
from . import ssl_match_hostname
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py", line 3, in <module>
from ssl import CertificateError, match_hostname
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 90, in <module>
import textwrap
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 40, in <module>
class TextWrapper:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py", line 82, in TextWrapper
whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
AttributeError: 'module' object has no attribute 'maketrans'
You should try
pip3 install tweepy
or...
pip install git+https://github.com/tweepy/tweepy.git
Based on what you are saying. I assume you are using python3. You can have a work-around to make this work by replacing this File
File
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/textwrap.py on line 82
From
whitespace_trans = string.maketrans(
to
whitespace_trans = str.maketrans(
This would make the code compile for python3 docs.
There is another installation option you could try that clones a repo from GitHub:
git clone https://github.com/tweepy/tweepy.git
cd tweepy
pip install .

Error with Crunchbase API wrapper pycrunchbase

I tried importing the pycrunchbase api wrapper and i get the following error.
It is a API wrapper that use the Crunchbase API platform
Doc: https://pycrunchbase.readthedocs.org/en/latest/usage.html
Github: https://github.com/ngzhian/pycrunchbase
>>> from pycrunchbase import *
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from pycrunchbase import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/__init__.py", line 1, in <module>
from .pycrunchbase import (
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/pycrunchbase.py", line 4, in <module>
from .resource import (
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/resource/__init__.py", line 1, in <module>
from .acquisition import Acquisition
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/resource/acquisition.py", line 3, in <module>
from .node import Node
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/resource/node.py", line 3, in <module>
from .relationship import NoneRelationshipSingleton, Relationship
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/resource/relationship.py", line 3, in <module>
from .page import Page
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/resource/page.py", line 4, in <module>
from .pageitem import PageItem
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pycrunchbase/resource/pageitem.py", line 58, in <module>
#six.python_2_unicode_compatible
AttributeError: 'module' object has no attribute 'python_2_unicode_compatible'
This is likely because your OS X is referencing an older version of six, that is not in your pip installed directory.
Pip installs in /Library/[..] while your system python installs in /System/Library/[..]
If you pip install six, it probably installs 1.9.0, but when you go into your python console, and type
>>> import six
>>> six.__version__
'1.4.1'
You'll probably get the above.
There's two options...the first and easiest is to just implement a virtualenv.
The second is to go to /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python and
$ rm six.py six.pyc
This will then force your console to reference your pip directory as opposed to your python dir, and the proper version will be referenced.
Hope that makes sense.
The pycrunchbase module has dependencies on the six and requests modules.
To get pycrunchbase working:
pip install requests six
And then you should be all set!

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