简体   繁体   English

Python:如何判断我的 Python 是否具有 SSL?

[英]Python: How can I tell if my python has SSL?

How can I tell if my source-built python has SSL enabled?如何判断我的源代码构建的 python 是否启用了 SSL? either要么

  • after running configure, but before compiling (best).在运行 configure 之后,但在编译之前(最好)。
  • after compiling, when I can run the python.编译后,什么时候可以运行python。

Context:背景:

  • a script that populates a bare linux box.一个填充裸linux框的脚本。
  • Prerequisite is to install openssl, so that Python can do https.前提是安装openssl,这样Python才能做https。
  • trying to detect if this prerequisite is not met.尝试检测是否不满足此先决条件。

If all you want to do is figure out if openssl is installed, you can parse the output of openssl version :如果您只想确定是否安装了openssl ,您可以解析openssl version的输出:

$ openssl version
OpenSSL 1.0.2g-fips  1 Mar 2016

You can get all sorts of information from version , for example, the directory where its stored:您可以从version获取各种信息,例如,其存储目录:

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

As far as Python goes, I'm not sure how you can tell before running configure (maybe check the contents of config.log ?) but once Python is installed;就 Python 而言,我不确定在运行 configure 之前如何判断(也许检查config.log的内容?)但是一旦安装了 Python; simply parse the output of ssl.OPENSSL_VERSION , like this:只需解析ssl.OPENSSL_VERSION的输出,如下所示:

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

For even more information, have a play with the sysconfig module, for example:有关更多信息,请使用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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM