python 报错 'module' object has no attribute 'HTTPSHandler'
young / / / 阅读量

 问题

Ansible从2.2升级到2.5后 执行yaml报错

ansible-playbook disk.yaml
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_K5RrUO/ansible_module_get_url.py", line 500, in 
from ansible.module_utils.urls import *
File "/tmp/ansible_K5RrUO/ansible_modlib.zip/ansible/module_utils/urls.py", line 414, in 
AttributeError: 'module' object has no attribute 'HTTPSHandler'

原因

源码安装的Python找不到SSL

[root@admin-ECS-001 Python-2.7.12]# python
Python 2.7.12 (default, Jan 5 2018, 14:03:19)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "", line 1, in 
File "/usr/local/lib/python2.7/ssl.py", line 60, in 
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl

首先安装好openssl,openssl-devel(centos) 后重新编译安装python

查看

[root@admin-ECS-001 yaml]# rpm -qa|grep openssl
openssl-devel-1.0.1e-57.el6.x86_64
openssl-1.0.1e-57.el6.x86_64

如果未安装请执行以下命令:

yum install openssl openssl-devel

 重新安装python

进入python源码目录,执行

./configure
Make && make install

测试结果

 

[root@admin-ECS-001 Python-2.7.12]# python
Python 2.7.12 (default, Jan 5 2018, 14:03:19)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl

(ssl加载成功)

 

PLAY RECAP *********************************************************************
172.16.16.73 : ok=2 changed=1 unreachable=0 failed=0

(ansible执行成功)

支付宝捐赠
请使用支付宝扫一扫进行捐赠
微信捐赠
请使用微信扫一扫进行赞赏
有 0 篇文章