配置 SSL 证书证书时,报错`ImportError: cannot import name UnrewindableBodyError`

问题描述

	Traceback (most recent call last):
  File "/usr/bin/tower-cli", line 11, in <module>
    load_entry_point('ansible-tower-cli==3.3.0', 'console_scripts', 'tower-cli')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 479, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2703, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2321, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2327, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/tower_cli/cli/run.py", line 17, in <module>
    from tower_cli.cli.base import TowerCLI
  File "/usr/lib/python2.7/site-packages/tower_cli/cli/base.py", line 25, in <module>
    from tower_cli.cli import misc
  File "/usr/lib/python2.7/site-packages/tower_cli/cli/misc.py", line 24, in <module>
    from requests.auth import HTTPBasicAuth
  File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  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

问题原因及解决方法

这似乎是请求的问题,而不是tower-cli。您能尝试按照以下步骤重新安装请求和urlib3来查看

# sudo pip uninstall requests
# sudo pip uninstall urllib3
# sudo yum remove python-urllib3
# sudo yum remove python-requests

通过执行以下命令,确认已删除所有上述库:

# rpm -qa | grep requests 
# pip freeze | grep requests

现在,使用yum安装这些软件包:

# sudo yum install python-urllib3
# sudo yum install python-requests

参考

https://github.com/ansible/tower-cli/issues/603