PyCURL: TLS Handshake Error

非 Y 不嫁゛ 提交于 2019-12-23 03:15:39

问题


I'm using PyCURL to test a redirection service we're offering- a user hits http://xyz.com/asdf/ and gets redirected to https://a.com, https://b.com and https://c.com.

I'm trying to use PyCURL to request http://xyz.com, and print out (but not HTTP request) the string "https://{a|b|c}.com", but whenever the destination URL is HTTPS and not HTTP, PyCURL.request() method throws the following exception:

(35, 'gnutls_handshake() failed: A TLS fatal alert has been received.')

Googling for "pycurl tls error" doesn't turn up many results, except one that hints that PyCURL for Ubuntu uses GnuTLS instead of OpenSSL. Is this what's causing my problem? If so, how do I configure PyCURL to use OpenSSL?

My OS is Ubuntu 9.10, Python 2.6, and here's my PyCURL version info

>>> pycurl.version_info()

(3, '7.19.5', 463621, 'x86_64-pc-linux-gnu', 1597, 'GnuTLS/2.8.3', 0, '1.2.3.3', ('tftp', 'ftp', 'telnet', 'dict', 'ldap', 'ldaps', 'http', 'file', 'https', 'ftps'), None, 0, '1.15')

Thanks in advance!


回答1:


I just resolved the same issue. I'm not 100% sure what was wrong. But I installed pycurl via apt-get install python-pycurl which i think by default uses gnutls, but it seemed to me it should be openssl on my system.

I resolved it by doing the following:

export PYCURL_SSL_LIBRARY=[openssl|gnutls|nss] (choose one of the 3, openssl,gnutls or nss, without the brackets)

pip install pycurl --upgrade

If your version of pycurl is already at the newest version, remove it by executing the following command pip uninstall pycurl and run the above commands.

source: http://pycurl.sourceforge.net/doc/install.html




回答2:


pycurl uses libcurl and libcurl can be built to use one of several TLS libraries. GnuTLS and OpenSSL being two of them. You can thus rebuild libcurl to use whichever of those that you prefer.



来源:https://stackoverflow.com/questions/1942719/pycurl-tls-handshake-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!