PythonとSSL

Page content

サーバー移転してから、コンパイルしたPythonでSSL接続しようとすると失敗していて「socket module has no ssl support」とか「No SSL support found」とか言われたので、原因を探っていたら発見しました。 それは、OpenSSLの場所を見つけられなかったということ。どうやら標準と違う場所にある場合は自分で指定する必要があったのです。

「Pythonソースディレクトリ/Modules/Setup」の中に「Socket module helper for SSL support」という部分があり、そこで場所を指定します。

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c 
    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl 
    -L$(SSL)/lib -lssl -lcrypto

「SSL=/usr/local/ssl」にOpenSSLのprefixを指定して、4行のコメントをはずし、コンパイルしなおします。

「python Pythonインストールディレクトリ/lib/pythonVERSION/test/test_socket_ssl.py」を実行すればSSLサポートが入っているかテストできます。 test_rude_shutdown …、test_basic …、test_timeout …の3行が表示されればOKです。