Python HTTPS下载失败,原因是“<urlopen error unknown url type:HTTPS>”

2024-05-05 06:01:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在一个非常小的系统(Ubuntu 16.04 docker image)上从源代码构建一个python2.7,它不会因为<urlopen error unknown url type: https>而导致HTTPS下载失败。我不想使用包管理器,但我知道这可以很容易地解决问题。在

我浏览了Unknown url type error in urllib2,并将不同的引用补丁应用到setup.py,将Modules/Setup和{}中的SSL变量设置为我传递给OpenSSL 1.1.1的./config --prefix的安装前缀,并将{}设置为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上研究包含完整构建日志的运行示例。在


Tags: installhttpsorggitmakeconfigureusrlocal
1条回答
网友
1楼 · 发布于 2024-05-05 06:01:36

我可以让它在<urlopen error [SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:661)>(我在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.dist和{}

     - 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 <somename.patch

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

相关问题 更多 >