【问题标题】:Python HTTPS download fails due to "<urlopen error unknown url type: https>"由于“<urlopen error unknown url type: https>”,Python HTTPS 下载失败
【发布时间】:2018-08-02 21:51:33
【问题描述】:

我正在尝试在一个非常小的系统(Ubuntu 16.04 docker 映像)上从源代码构建 Python 2.7,它不会由于 &lt;urlopen error unknown url type: https&gt; 而导致 HTTPS 下载失败。我不想使用包管理器,但我知道这很容易解决问题。

我检查了Unknown url type error in urllib2 并将不同的引用补丁应用到setup.py,将Modules/SetupModules/Setup.dist 中的SSL 变量设置为我传递给OpenSSL 1.1.1 的./config --prefix 的安装前缀并将 LD_LIBRARY_PATH 设置为 OpenSSL 安装前缀。

我怀疑这样一个最小的系统需要修复的东西比另一个答案中建议的要多。为什么configure 没有--with-ssl 开关?

构建脚本是

apt-get update && apt-get install --yes wget xz-utils make gcc patch
wget http://www.cpan.org/src/5.0/perl-5.26.1.tar.gz && tar xf perl-5.26.1.tar.gz && cd perl-5.26.1 && ./configure.gnu && make -j16 && make install && cd ..
wget https://ftp.gnu.org/pub/gnu/gettext/gettext-0.19.8.1.tar.xz && tar xf gettext-0.19.8.1.tar.xz && cd gettext-0.19.8.1 && ./configure && make -j16 && make install && cd ..
wget https://www.zlib.net/zlib-1.2.11.tar.gz && tar xf zlib-1.2.11.tar.gz && cd zlib-1.2.11 && ./configure && make -j16 && make install && cd ..
wget https://www.kernel.org/pub/software/scm/git/git-2.13.3.tar.gz && tar xf git-2.13.3.tar.gz && cd git-2.13.3 && ./configure --with-perl=/usr/local/bin/perl && make -j16 && make install && cd ..
            # need `--with-perl` passed to `configure` because the `/usr/local/bin/perl` isn't picked up regardless where it's found in PATH, see https://stackoverflow.com/questions/48931247/cant-locate-extutils-makemaker-pm-in-inc-during-git-build for details
wget https://www.openssl.org/source/openssl-1.1.1-pre1.tar.gz && tar xf openssl-1.1.1-pre1.tar.gz && cd openssl-1.1.1-pre1 && ./config --prefix=/usr/local/openssl && make -j16 && make install && cd ..
            # need to install into explicit prefix different from `/usr/local` in order to make OpenSSL get picked up by Python's patched `configure` (specifying `OPENSSL_ROOT=/usr/local` doesn't work)
wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz && tar xf Python-2.7.14.tgz && cd Python-2.7.14 && wget https://gist.githubusercontent.com/rkitover/2d9e5baff1f1cc4f2618dee53083bd35/raw/7f33fcf5470a9f1013ac6ae7bb168368a98fe5a0/python-2.7.14-custom-static-openssl.patch && patch -p1 <python-2.7.14-custom-static-openssl.patch && env OPENSSL_ROOT=/usr/local/openssl ./configure --disable-shared && make -j16 && make install && cd ..
git clone git://git.gnome.org/jhbuild && cd jhbuild && ./autogen.sh --prefix=/usr/local && make && make install && cd ..
env JHBUILD_RUN_AS_ROOT= jhbuild bootstrap

我选择jhbuild bootstrap 作为测试命令,因为这是我们想要的结果,请随时提出更好的建议。

我在 https://gitlab.com/krichter/jhbuild-docker-build 创建了一个 SSCCE,它允许在 GitLab CI 中运行构建脚本,并且可以在 https://gitlab.com/krichter/jhbuild-docker-build/-/jobs/53948513 调查包含完整构建日志的示例运行。

【问题讨论】:

  • 当您配置所有正在构建的包时,您应该添加一个RPATH,以便在运行时使用相同的库。我希望看到所有配置都包含LDFLAGS += -L/usr/local/lib -Wl,-R,/usr/local/lib -Wl,--enable-new-dtags 之类的内容。
  • @jww 谢谢你的提示。我刚刚开始学习 rpath,但还不能完全理解“我期望......”的意思。你的意思是我必须修补 OpenSSL 和 Python 的 configconfigure 吗?或者运行./configure --prefix=... LDFLAGS+='-L/usr/local/lib -Wl,-R,/usr/local/lib -Wl,--enable-new-dtags'
  • 我需要在Modules/Setup.dist的补丁中添加一些东西吗?
  • 结帐Noloader | Build-Scripts。构建脚本与您尝试执行的操作类似,但它使用 Git、SSH、Wget 和其他几个程序来执行它们。它甚至有时必须修补源文件和配置文件。它不构建 PHP,但这样做应该很容易。
  • 您应该考虑以合作者的身份加入Build-Scripts。我们似乎有很多重叠。这些脚本已经存在了一段时间,所以它们相当成熟。它们也是跨平台的。我认为将 Python 添加到构建脚本中比重新发明和修复轮子要容易得多。例如,缺少运行路径和 dtag,以及缺少 OpenSSL 和 Git 的选项。

标签: python docker ssl build openssl


【解决方案1】:

之后我可以用&lt;urlopen error [SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:661)&gt;(我在 FIXME 处理)让它失败

  • --prefix=/usr/local/ --openssldir=/usr/local 添加到 OpenSSL 的config
  • 应用https://gist.githubusercontent.com/rkitover/2d9e5baff1f1cc4f2618dee53083bd35/raw/7f33fcf5470a9f1013ac6ae7bb168368a98fe5a0/python-2.7.14-custom-static-openssl.patch,如上面引用的问题中所述,并且
  • 修补 Modules/Setup.distModules/Setup

    --- Modules/Setup.dist  2018-02-23 01:12:46.537415323 +0100
    +++ Modules/Setup.dist.d    2018-02-23 01:44:45.235092890 +0100
    @@ -215,10 +215,10 @@
    
     # 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 _ssl.c \
    +   -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
    +   -L$(SSL)/lib -lssl -lcrypto
    
     # The crypt module is now disabled by default because it breaks builds
     # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
    

    (patch -u -p0 &lt;somename.patch)

可以在https://gitlab.com/krichter/jhbuild-docker-build/-/jobs/53978734 找到克服初始错误的示例构建。

【讨论】:

  • 您应该在问题中添加附加信息;而不是作为答案。
  • 这解决了这个问题。由于 python 的构建过程非常接近于可怕,我预计在新的构建问题之后会出现一些构建问题,并且不值得通过编辑它或使问题过长来破坏我一天收集的信息。
猜你喜欢
  • 2018-12-04
  • 2018-08-03
  • 1970-01-01
  • 1970-01-01
  • 2012-12-11
  • 1970-01-01
  • 2019-08-09
  • 2015-04-07
  • 2014-02-25
相关资源
最近更新 更多