Python:我怎么知道我的python是否有SSL?

时间:2016-05-05 16:17:21

标签: python ssl

如何判断源代码构建的python是否启用了SSL?任

  • 运行configure后,但在编译之前(最好)。
  • 编译后,我可以运行python。

上下文:

  • 一个填充裸Linux框的脚本。
  • 先决条件是安装openssl,以便Python可以执行https。
  • 尝试检测是否未满足此先决条件。

1 个答案:

答案 0 :(得分:11)

如果要做的只是确定是否安装了openssl,您可以解析openssl version的输出:

$ openssl version
OpenSSL 1.0.2g-fips  1 Mar 2016

您可以从version获取all sorts of information,例如,其存储的目录:

$ openssl version -d
OPENSSLDIR: "/usr/lib/ssl"

就Python而言,我不确定在运行configure之前你怎么知道(也许检查config.log的内容?)但是一旦安装了Python;只需解析ssl.OPENSSL_VERSION的输出,如下所示:

$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2g-fips  1 Mar 2016

有关更多信息,请使用sysconfig模块,例如:

$ python -c "import sysconfig; print(sysconfig.get_config_var('CONFIG_ARGS'))"
'--enable-shared' '--prefix=/usr' '--enable-ipv6' '--enable-unicode=ucs4' '--with-dbmliborder=bdb:gdbm' '--with-system-expat' '--with-computed-gotos' '--with-system-ffi' '--with-fpectl' 'CC=x86_64-linux-gnu-gcc' 'CFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security ' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'