scrapy是python网页抓取框架, 是编写爬虫的利器,但是新手在安装的时候经常会遇到各种问题, 今天我们就来看一个openssl版本引起的问题,遇到这个问题,我们需要的是给openssl打补丁。
[python@pythontab dev]$ sudo pip install scrapy … OpenSSL/ssl/connection.c: In function ‘ssl_Connection_set_context’: OpenSSL/ssl/connection.c:289: warning: implicit declaration of function ‘SSL_set_SSL_CTX’ OpenSSL/ssl/connection.c: In function ‘ssl_Connection_get_servername’: OpenSSL/ssl/connection.c:313: error: ‘TLSEXT_NAMETYPE_host_name’ undeclared (first use in this function) OpenSSL/ssl/connection.c:313: error: (Each undeclared identifier is reported only once OpenSSL/ssl/connection.c:313: error: for each function it appears in.) OpenSSL/ssl/connection.c:320: warning: implicit declaration of function ‘SSL_get_servername’ OpenSSL/ssl/connection.c:320: warning: assignment makes pointer from integer without a cast OpenSSL/ssl/connection.c: In function ‘ssl_Connection_set_tlsext_host_name’: OpenSSL/ssl/connection.c:346: warning: implicit declaration of function ‘SSL_set_tlsext_host_name’ error: command ‘gcc’ failed with exit status 1
报错了。
通过分析上面的错误可以看出是ssl的问题,原来是pyopenssl 0.13的版本和openssl不兼容,需要打补丁。
下面说一下给pyOpenSSL打补丁的方法:
[python@pythontab dev]$ wget https://bugs.launchpad.net/pyopenssl/+bug/845445/+attachment/2666639/+files/pyOpenSSL-0.13.centos5.patch thanks to Philip K. Warren (pkwarren) [python@pythontab dev]$ wget http://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.13.tar.gz [python@pythontab dev]$ grep “#define OPENSSL_VERSION_TEXT” /usr/include/openssl/opensslv.h #define OPENSSL_VERSION_TEXT “OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008″ #define OPENSSL_VERSION_TEXT “OpenSSL 0.9.8e-rhel5 01 Jul 2008″ [python@pythontab dev]$ mv *.patch pyOpenSSL-0.13 [python@pythontab dev]$ cd pyOpenSSL-0.13 [python@pythontab pyOpenSSL-0.13]$ patch -p1 < pyOpenSSL-0 centospatchbr style='font-size:13px;font-style:normal;font-weight:normal;color:rgb(51, 51, 51);' />patching file OpenSSL/ssl/connection.c patching file OpenSSL/ssl/context.c [python@pythontab pyOpenSSL-0.13]$ sudo python setup.py install [python@pythontab dev]$ sudo pip install –upgrade scrapy
好了,现在scrapy安装成功。
如果还有不明白的地方,欢迎留言提问!