ども、最近疲れてるかもの cloudpackかっぱ (@inokara) です。

はじめに

httpie か fabric をインストールしたタイミングからか以下のような aws-cli を叩くと以下のようなエラーが出るようになってしまった@MacOS X Mavericks を前に途方にくれて焦ったのでメモです。

Traceback (most recent call last):
  File "/usr/local/bin/aws", line 15, in 
    import awscli.clidriver
  File "/Library/Python/2.7/site-packages/awscli/clidriver.py", line 16, in 
    import botocore.session
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 27, in 
    import botocore.credentials
  File "/Library/Python/2.7/site-packages/botocore/credentials.py", line 29, in 
    from botocore.utils import InstanceMetadataFetcher, parse_key_val_file
  File "/Library/Python/2.7/site-packages/botocore/utils.py", line 22, in 
    from botocore.vendored import requests
  File "/Library/Python/2.7/site-packages/botocore/vendored/requests/__init__.py", line 53, in 
    from .packages.urllib3.contrib import pyopenssl
  File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/contrib/pyopenssl.py", line 55, in 
    orig_connectionpool_ssl_wrap_socket = connectionpool.ssl_wrap_socket
AttributeError: 'module' object has no attribute 'ssl_wrap_socket'

メモ

症状

aws ec2 とか叩くだけで上記のようなエラーがでてしまう…

Traceback (most recent call last):
  File "/usr/local/bin/aws", line 15, in 
    import awscli.clidriver
  File "/Library/Python/2.7/site-packages/awscli/clidriver.py", line 16, in 
    import botocore.session
  File "/Library/Python/2.7/site-packages/botocore/session.py", line 27, in 
    import botocore.credentials
  File "/Library/Python/2.7/site-packages/botocore/credentials.py", line 29, in 
    from botocore.utils import InstanceMetadataFetcher, parse_key_val_file
  File "/Library/Python/2.7/site-packages/botocore/utils.py", line 22, in 
    from botocore.vendored import requests
  File "/Library/Python/2.7/site-packages/botocore/vendored/requests/__init__.py", line 53, in 
    from .packages.urllib3.contrib import pyopenssl
  File "/Library/Python/2.7/site-packages/botocore/vendored/requests/packages/urllib3/contrib/pyopenssl.py", line 55, in 
    orig_connectionpool_ssl_wrap_socket = connectionpool.ssl_wrap_socket
AttributeError: 'module' object has no attribute 'ssl_wrap_socket'

原因

botocore が利用している ndg-httpsclient が悪さしているようでした。

botocore explodes when installed alongside pyOpenSSL, ndg-httpsclient and pyasn1

環境

% python --version
Python 2.7.5
% pip freeze | egrep 'awscli|botocore|pyopenssl|pyasn1|ndg-httpsclient'
awscli==1.6.8
botocore==0.78.0
ndg-httpsclient==0.3.2
pyasn1==0.1.7

ndg-httpsclient==0.3.2 このバージョンを下げることで対応しました。

sudo pip install ndg-httpsclient==0.3.1

はあ…

ヤレヤレです。

元記事はこちらです。
aws-cli で 'module' object has no attribute 'ssl_wrap_socket' こんなエラーが出たので焦ったからメモ