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

Mar*_*son 8 python ssl

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

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

语境:

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

Bur*_*lid 13

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

$ openssl version
OpenSSL 1.0.2g-fips  1 Mar 2016
Run Code Online (Sandbox Code Playgroud)

您可以从例如其存储的目录中获取各种信息version:

$ openssl version -d
OPENSSLDIR: "/usr/lib/ssl"
Run Code Online (Sandbox Code Playgroud)

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

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

有关更多信息,请参阅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'
Run Code Online (Sandbox Code Playgroud)