当我尝试在 Ubuntu 14.04.2 上使用 Python 2.7 中的https://
PycURL从 URL 下载时,我收到了'PycURL/7.19.3 libcurl/7.35.0 GnuTLS/2.12.23 zlib/1.2.8 libidn/1.28 librtmp/2.3'
pycurl.error: (35, 'gnutls_handshake() failed: Handshake failed')
curl
但是,工作正常,可能是因为它使用了openssl
:
$ curl --version
curl 7.35.0 (x86_64-pc-linux-gnu) libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
所以我更喜欢 PycURL 绑定openssl
。我尝试python-pycurl
使用
export PYCURL_SSL_LIBRARY=openssl
sudo apt-get remove python-pycurl
sudo apt-get install python-pycurl
正如在类似问题上经常建议的那样,但仍然pycurl
不局限于。和等也openssl
一样。apt-get remove
easy_install
问题:如何获取具有绑定的 PycURL openssl
?
附加问题:为什么 PycURL 没有openssl
立即安装绑定,因为 GnuTLS 绑定似乎不起作用?
答案1
我真心希望这个问题可以得到解决,而不用遵循一些我几乎不懂的指令和编译东西等等。但不幸的是...
看这个要点从 2014 年开始获取说明。
在撰写本文时,使用的是 Ubuntu Trusty 14.04.2 LTS,版本仍然相同,即7.19.3
,因此可以逐一遵循 Gist 中的说明。抽样检查没有问题,并且 curl 仍可与一起使用https://
。逐步完成配方后,pycurl.version
显示
PycURL/7.19.3 libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
为了自动下载、修补和编译,你会喜欢这个小脚本:
#!/bin/bash
#
# How to rebuild PycURL against OpenSSL on Ubuntu
# (tested for 14.04.2 now)
#
# This script implements the great Gist by aerickson:
# https://gist.github.com/aerickson/f15133a7e56b2d7f27e3
# feel free to use it anyway you like.
# Credits go to Andrew anyway :)
#
# we will add some colored headers that make it easier to find obstacles
# in the terminal output (which will be > 1000 lines...)
ESC="\x1b["
RESET=$ESC"39;49;00m"
RED=$ESC"31;01m"
GREEN=$ESC"32;01m"
YELLOW=$ESC"33;01m"
BLUE=$ESC"34;01m"
header() {
echo -e "\n$YELLOW --- $1 --- $RESET\n"
}
echo -e "\n\n$GREEN"
echo -e "\
Build pycurl with openssl support\n\n\
Section numbers refer to\n\
https://gist.github.com/aerickson/f15133a7e56b2d7f27e3
"
echo -e "$RESET\n"
# remove eventually existing pycurl
header "0. remove python-pycurl"
sudo apt-get remove python-pycurl --yes
header "1. install build essentials"
sudo apt-get install build-essential fakeroot dpkg-dev --yes
header "2./3. make build dir"
mkdir ~/python-pycurl-openssl
cd ~/python-pycurl-openssl
if [ ! "$HOME/python-pycurl-openssl" = `pwd` ]; then
echo -e "\n${RED}Cannot change to working dir. WTF?${RESET}\n"
exit 1
fi
header "4. get pycurl sources"
sudo apt-get source python-pycurl --yes
header "5. get build dependencies for python-pycurl"
sudo apt-get build-dep python-pycurl --yes
header "6. install libcurl with openssl"
sudo apt-get install libcurl4-openssl-dev --yes
DIR=`find * -name 'pycurl*' -type d -print`
DSC=`find * -name '*.dsc' -type f -print`
echo
echo "DIR = $DIR"
echo "DSC = $DSC"
echo
header "7. unpack source archive"
sudo dpkg-source -x $DSC
header "8. change to package dir"
cd $DIR
header "9. edit debian/control file"
sudo cp debian/control ./control.gnutls
sudo cat ./control.gnutls | sed -e 's|libcurl4-gnutls-dev|libcurl4-openssl-dev|' | sudo tee ./control.openssl >/dev/null
sudo cp ./control.openssl debian/control
header "10. build package"
echo "hold on..."
echo "(crashdump of nosetests is 'normal')"
sudo PYCURL_SSL_LIBRARY=openssl dpkg-buildpackage -rfakeroot -b 2>&1 | sudo tee ../buildlog.txt >/dev/null
echo
echo -e $BLUE
sudo head ../buildlog.txt
echo -e $RESET
echo " [ ... 1000+ more messages omitted ... ]"
echo -e $BLUE
sudo tail ../buildlog.txt
echo -e $RESET
echo
echo "find more output in ~/python-pycurl-openssl/buildlog.txt:"
wc -l ../buildlog.txt
header "11. install via package manager"
sudo dpkg -i ../python-pycurl_*.deb
echo
echo "some other packages are available also now:"
ls ../*.deb
echo "they can be installed by 'sudo dpkg -i ../py...' from here."
不过,希望新版本7.19.5
能够进入仓库,应该修复 GnuTLS 中的问题,以便 PycURL 可以立即使用。但问题仍然存在,为什么这个问题会出现在存储库中自 2009 年起没人关心……
更新问题
有趣的是,任何后续的 Ubuntu pycurl/libcurl 常规更新都会覆盖您的更改。所以准备好一遍又一遍地重复这一操作 :(
或者,你可以python-pycurl
暂停后构建它以openssl
确保apt-get update
不会再覆盖它:
sudo apt-mark hold python-pycurl
稍后可以通过以下方式重新启用更新
sudo apt-mark unhold python-pycurl
覆盆子食谱
上述脚本在 Raspberry Pi 和 Raspbian Wheezy 上也能很好地运行,只要你添加安装源的功能即可。
sudo nano /etc/apt/sources.list
并取消注释该deb-src
行,这样文件将看起来像
deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
# Uncomment line below then 'apt-get update' to enable 'apt-get source'
deb-src http://archive.raspbian.org/raspbian/ wheezy main contrib non-free rpi
当找不到源时(在步骤 4 中),您可能需要执行
sudo apt-get update
在运行上述脚本之前。
注意:在 Raspberry 上,该过程会受到处理器速度的影响,因此您应该留出半个小时(如果一切顺利)。同样,您要么暂停,python-pycurl
要么每次更新后都必须再次投入这半个小时。